Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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