Rxxxx
Rxxxx

Reputation: 706

How to emulate key presses in vim script

my question is similar to this one https://superuser.com/questions/277051/how-can-i-emulate-key-presses-on-vim-startup

I'm using the plugin netrw in my vim instead of nerdtree in that question. I add the following line to enable netrw automatically.

autocmd BufWinEnter * :Ve

While open vim, I need to press ^W^W each time because the active buffer is the left one, where the netrw is located.

How can I make vim emulate these key presses on startup? In fact, I've got it works before, but I didn't save my .vimrc in a recently re-installation of OS.

The answer of that question doesn't work for me.

My environment: Mac OS X 10.9.5 MacVim Snapshot 73

Any answers appreciated, thanks a lot :)

Upvotes: 3

Views: 1732

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172560

Best way is by just appending the command to the existing :autocmd (separated by |):

autocmd BufWinEnter * Vexplore | wincmd w

Notes

  • By using BufWinEnter, this will open a netrw split on each displaying of a buffer. If you just want to trigger this once at Vim startup, VimEnter is the right event to use.
  • Don't abbreviate commands inside plugins and configuration; this is just to save keys on interactive use. It's easier to understand this way, and you don't have the risk of having to adapt all instances when you install / define another command with the same initial letters (e.g. :VerticalSplit). Also, you don't need the : in autocmds.
  • For <C-W> window commands, there's the special :wincmd Ex command to trigger those. For all else, you would use :execute 'normal! \<C-w>\<C-w>'.

Upvotes: 1

Related Questions