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.

When I run vim, the NerdTree plugin opens a project explorer. I achieved this by adding the following line to my .vimrc file:

autocmd VimEnter * NERDTree

It opens two buffers but unfortunately I need to press ^W^W each time because the active buffer is the left one, where the NerdTree is located.

How can I make vim emulate these key presses on startup?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

There are a couple of ways to give Vim keypresses in a command. The general way is to use the :normal command, which in this case would be

:execute "normal \<C-W>\<C-W>"

where the :execute command is needed to expand the control characters. For normal commands that begin with Ctrl-W, however, the :wincmd command can be simpler to use, e.g.,

:wincmd w

where in this case I've taken advantage of the fact that Ctrl-W Ctrl-W and Ctrl-W w do the same thing. Your autocommand would then be

autocmd VimEnter * wincmd w

See

:help :normal
:help :wincmd
:help CTRL-W_w
share|improve this answer
    
Great answer and works perfectly, many thanks! –  gennad Apr 29 '11 at 17:13
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.