0

hi i'm new to vim but i'm loving it. with NERDtree plugin i want to have a little script then when i open a file (.cpp or .h) it opens automatically the .h and .cpp splitted with .h in uppeer split and .cpp in lower, with a fixed split point.

what to do now is: open file.cpp in nerdtree with 'o', command ':sp file.h', resize the split line

2 Answers 2

2

The alternate plugin can create a split with the pair file. You can probably add you own key mappings to NERDTree.vim to do this automatically.

2
  • i have no idea how to do it but thanks alternate plugin seems to be a great plugin
    – nkint
    Apr 27, 2011 at 13:57
  • map, nmap, vmap commands. alternate.vim registers multiple functions like AlternateFile. You can map a function to a key (call functionname). I guess that's what you need. I'm not too experienced in vimscript, but there's certainly someone on StackOverflow who can help :) Apr 27, 2011 at 14:24
0

If you want to have the .cpp or .h file open automatically whenever you open the other file, put these lines in your ~/.vimrc:

au BufRead,BufNewFile *.h exe "bel split" fnameescape(expand("<amatch>:r").".cpp")
au BufRead,BufNewFile *.cpp exe "split" fnameescape(expand("<amatch>:r").".h")

Both windows should be the same height unless you have turned the 'equalalways' option off.

1
  • thanks. this does not match opening files with Nerdtree
    – nkint
    Apr 27, 2011 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .