3

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 :)

Community
  • 1
  • 1
Rxxxx
  • 706
  • 7
  • 7

1 Answers1

1

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>'.
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Thanks for your answer, I know the difference between BufWinEnter and VimEnter, BufWinEnter is what I want. I've tried autocmd BufWinEnter * Vexplore | wincmd w and even :execute 'normal! \\' but all doesn't work.... – Rxxxx Mar 25 '15 at 10:35
  • Does it work when you type it: `:Vexplore | wincmd w` (it does for me)? Do you have other autocmds? – Ingo Karkat Mar 25 '15 at 10:51