In my .vimrc, I've got the lines

autocmd VimEnter * NERDTree
autocmd VimEnter * TagbarOpen

This results in a layout with two sidebars and a centre column containing the main editing buffer (i.e. the file I'm editing), but with the cursor in the NERDTree sidebar - resulting in the Tagbar being collapsed by default. What I want to do is execute the keystroke combination <C>l (which I've mapped to the command to move the cursor one buffer to the right) between the NERDTree opening and the Tagbar being toggled - but so far, I haven't managed to get the cursor to move. So far, i've tried using both

autocmd VimEnter * <C>l
autocmd VimEnter * normal <Ctrl+l>

... between the two above first lines, but neither of these work.

How do I go about this?

  • 1
    possible duplicate of VIM Executing a key command in a function
    – savanto
    Jun 5, 2014 at 23:44
  • See the link above. You can put execute "normal \<C-L>" in your .vimrc.
    – savanto
    Jun 5, 2014 at 23:49
  • 1
    That solution and the answers in the linked-to question don't work.
    – Jules
    Jun 6, 2014 at 1:22
  • You're right, the questions are not really duplicates. I've combined the information from that link with what you had so far. Please take a look below and let me know if it works.
    – savanto
    Jun 6, 2014 at 3:31

2 Answers 2


The command to go to the window to the right is <C-w>l. You can execute that with

:execute "normal! \<C-w>l"

But for the <C-w> commands, there's a special :wincmd that makes this easier. So just skip your custom mapping, and do:

autocmd VimEnter ...
autocmd VimEnter * wincmd l

Upon further consideration, I admit that the question is not really a duplicate of VIM Executing a key command in a function.

You were on the right track with autocmd VimEnter, you were missing the execute command:

:help execute
:exe[cute] {expr1} ..   Executes the string that results from the evaluation    
                        of {expr1} as an Ex command.

Taking the syntax for executing a key combination such as Ctrl-L from the above link, you can combine the two in your .vimrc:

autocmd VimEnter * execute "normal \<C-L>"

You must log in to answer this question.

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