Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nerdtree auto focus to file when opened in new tab

Tags:

vim

nerdtree

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

like image 730
Sairam Avatar asked Nov 25 '10 13:11

Sairam


People also ask

Is NERDTree a buffer?

This is a NERDTree plugin that highlights all visible nodes that are open in Vim. It also maps a key w to close (wipeout) the buffer associated with the current node.


2 Answers

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
like image 104
Yohann Avatar answered Oct 09 '22 03:10

Yohann


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.

like image 31
dnets Avatar answered Oct 09 '22 04:10

dnets