I want a file to be opened in a new tab when I enter or double click it. I know there is t shortcut but I always open a file in a new tab and enter is more confortable for me.
7 Answers
s will open the file currently under the cursor in a new vertically split window. Use t to open in a new tab.

- 1,421
- 1
- 16
- 19
-
Nice. This closes NERDTree window. Is there anyway to keep it open. – Bakul G May 13 '20 at 20:47
-
2Found that 'T' opens in new tab – Bakul G May 13 '20 at 20:48
Try adding
let NERDTreeMapOpenInTab='\r'
or
let NERDTreeMapOpenInTab='<ENTER>'
to your .vimrc
.

- 50,406
- 14
- 85
- 110
-
24
-
3
-
2
-
There is this NerdTree + tabs plugin: https://github.com/jistr/vim-nerdtree-tabs could be useful. – anh_ng8 Oct 11 '16 at 12:02
-
While this technically answers the question, it renders directories inaccessible. – oarfish Oct 29 '17 at 20:50
-
1@alice @oarfish try this: `let NERDTreeMapActivateNode='v'` - you can use the `v` key to open/close directory nodes. – bvpx Dec 13 '17 at 19:54
As described in section NERDTreeCustomOpenArgs of the NerdTree help, you can use this option to control the opening behavior of files and directories. Add the following statement to your .vimrc
:
let NERDTreeCustomOpenArgs={'file':{'where': 't'}}
This ensures in this case that only files in a new tab are opened. All other combinations can be found in the help.

- 171
- 1
- 6
You may want to add https://github.com/Nopik/vim-nerdtree-direnter plugin as well - it fixes the directory opening problem, so enter on directory node will just expand/collapse, not open new tab.

- 542
- 1
- 4
- 15
-
2Tried, this, but didn't work: https://github.com/Nopik/vim-nerdtree-direnter/issues/1 – sixtyfootersdude Dec 02 '15 at 17:15
I use following map to do tab traverse :
nnoremap <C-l> gt
nnoremap <C-h> gT

- 2,673
- 4
- 30
- 33

- 102
- 1
- 4
-
Also, would this not conflict the default mapping of moving between split panes? Because I have tried doing exactly this. – Aman Oct 05 '20 at 13:07
Add this to the plugin. It needs to be added to a file such as: ~/.vim/nerdtree_plugin/mymapping.vim
. The exact location will depend on what plugin manager you use for vim. e.g. for Plugged it is ~/.vim/plugged/nerdtree/nerdtree_plugin/mymapping.vim
This code adds a mapping for the enter key to open files in a new tab while just expanding/collapsing directories. For the new tabs it also mirrors the NERDTree so it can be shared between tabs.
call NERDTreeAddKeyMap({
\ 'key': '<CR>',
\ 'scope': "Node",
\ 'callback': 'OpenInNewTab',
\ 'quickhelpText': 'open node' })
" FUNCTION: s:openInNewTab(target) {{{1
function! OpenInNewTab(node)
if a:node.path.isDirectory
call a:node.activate()
else
call a:node.activate({'where': 't'})
call g:NERDTreeCreator.CreateMirror()
wincmd l
endif
endfunction

- 2,852
- 2
- 25
- 35
-
Will this be overwritten if I need to update the plugin? I assume it will if I delete then reinstall it. – Sep 15 '17 at 14:43
For the double-click event specifically, it is (only?) possible by slightly changing the NERDtree source code (posted here):
-
2
-
Changing the source code is a very bad idea, especially since NerdTree offers a lot of options for configuration. – chrboesch Jun 16 '20 at 07:31