Running a vim key combination on startup

vim
5,183

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
Share:
5,183

Related videos on Youtube

Jules
Author by

Jules

Expert Python programmer with experience working with the Linux network stack, REST APIs, and relational databases (and Postgres in particular). There's some devops experience in there too, but software dev is my preference. Not currently open to new work.

Updated on September 18, 2022

Comments

  • Jules
    Jules over 1 year

    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?

    • savanto
      savanto almost 10 years
    • savanto
      savanto almost 10 years
      See the link above. You can put execute "normal \<C-L>" in your .vimrc.
    • Jules
      Jules almost 10 years
      That solution and the answers in the linked-to question don't work.
    • savanto
      savanto almost 10 years
      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.