Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|improve this answer
    
i have no idea how to do it but thanks alternate plugin seems to be a great plugin – nkint Apr 27 '11 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 :) – Tamás Szelei Apr 27 '11 at 14:24

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.

share|improve this answer
    
thanks. this does not match opening files with Nerdtree – nkint Apr 27 '11 at 16:32

You must log in to answer this question.

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