nerdtree auto focus to file when opened in new tab
Asked Answered
V

3

28

I am using NerdTree on Linux . I would like to jump from the nerd tree buffer to the file buffer after opening a file in a new tab using 't'. I need to press 'Ctrl+W+W' all the time.

Any idea about how to have vi execute C-W-W after a new buffer is created .

Sairam

Velvavelvet answered 25/11, 2010 at 13:55 Comment(0)
S
-3

Simply add autocmd BufNew * wincmd l to your .vimrc

Syriac answered 25/11, 2010 at 17:31 Comment(2)
For future travelers: This doesn't work for me (vim 7.2), but putting PaulP's solution in .vimrc after the the line autocmd vimenter * NERDTree did the trickDisengagement
Yohann's solution worked for me, not this one. Not sure if this is out of date or not, but definitely is very similar.Blimey
B
93

When vim starts, it opens a window for the file, then it opens another window for NerdTree.

The easiest way to come back to the main window is just to jump to the previous window like this:

" Start NERDTree
autocmd VimEnter * NERDTree
" Go to previous (last accessed) window.
autocmd VimEnter * wincmd p
Braunstein answered 12/10, 2013 at 3:1 Comment(5)
exactly what i needed! when opening a file with vim, this sets focus to the newly opened file while still opening NERDTreeCavalier
You can combine commands: autocmd VimEnter * NERDTree | wincmd pMiddlemost
perfect thanks got here by searching vimenter windowInterfertile
This works actually. Combining as @Middlemost says doesn't works for me, not sure why.Vena
to make NERDTree open on startup and stay focus on nerdtree if no files specified autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | else | NERDTree | wincmd p | endif Quip
A
4

You can use so-called autocommands, like:

  au BufNew * <command>

It will execute command when new buffer is created. Start from there. Check out vimdoc on the subject.

Abidjan answered 25/11, 2010 at 17:6 Comment(0)
S
-3

Simply add autocmd BufNew * wincmd l to your .vimrc

Syriac answered 25/11, 2010 at 17:31 Comment(2)
For future travelers: This doesn't work for me (vim 7.2), but putting PaulP's solution in .vimrc after the the line autocmd vimenter * NERDTree did the trickDisengagement
Yohann's solution worked for me, not this one. Not sure if this is out of date or not, but definitely is very similar.Blimey

© 2022 - 2024 — McMap. All rights reserved.