1

I usually open code.h and code.cpp at the same time.
And display them side by side vertically in a window.

Currently I use:

$ vim -O code.{h,cpp}

If vim can run some commands(to manipulate filename) just before opening a file,
I can simply use:

$ vim code

How can I write this kind of vim-script?


Edit:

file_line.vim is great.

2 Answers 2

2

Given this:

and :help autocmd-event, you should be able to use BufReadPre event for doing something before buffer is read:

BufReadPre            starting to edit a new buffer, before reading the file
0
1

In this case, a possible solution is to modify the argument list (see :help arglist) on Vim startup. It can be done using a VimEnter auto-command that iterates over the argument list and replaces items not corresponding to existing files with those items concatenated with certain suffixes, as follows.

autocmd VimEnter * call AddArgsSuffixes(['.h', '.cpp'])
function! AddArgsSuffixes(sfx)
    let args = []
    for f in argv()
        if filereadable(f)
            call add(args, f)
        else
            for s in a:sfx
                call add(args, f . s)
            endfor
        endif
    endfor
    exe 'args' join(map(args, 'fnameescape(v:val)'))
endfunction
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.