0

I currently have the following in my .vimrc:

au VimEnter * NERDTree
au BufWinEnter * NERDTreeMirror

This I believe launches NERDTree when I open Vim, as well as when I open a new tab using a plugin. Currently, when I launch Vim using

vim

at the command line, the cursor is sitting in NERDTree ready for me to navigate my files, which is great. However, when I use

vim my-file.txt

the cursor remains in the NERDTree window. I'm aware that I can add this to my .vimrc:

au BufNew * wincmd l

But that means the cursor will always be placed in the window to the right of NERDTree, even if I don't specify a file.

Does anyone have any ideas?

Stuart Memo
  • 1,138
  • 4
  • 14
  • 30

1 Answers1

3

You can make the command conditional on whether arguments were passed to Vim:

:au VimEnter * if argc() > 0 | wincmd l | endif

(I'd use the VimEnter event for that; just make sure this autocmd comes after the one that opens NERDTree.)

PS: There are a couple of related questions here:

Community
  • 1
  • 1
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324