How to open a file in new tab by default in NERDTree?

VimNerdtree

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

s will open the file currently under the cursor in a new vertically split window. Use t to open in a new tab.

Solution 2 - Vim

Try adding

let NERDTreeMapOpenInTab='\r'

or

let NERDTreeMapOpenInTab='<ENTER>'

to your .vimrc.

Solution 3 - Vim

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.

Solution 4 - Vim

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.

Solution 5 - Vim

I use following map to do tab traverse :

nnoremap <C-l> gt
nnoremap <C-h> gT

Solution 6 - Vim

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

Solution 7 - Vim

For the double-click event specifically, it is (only?) possible by slightly changing the NERDtree source code (posted here):

https://stackoverflow.com/a/31570970/5144840

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaliceView Question on Stackoverflow
Solution 1 - VimalexView Answer on Stackoverflow
Solution 2 - VimZsolt BotykaiView Answer on Stackoverflow
Solution 3 - VimNopikView Answer on Stackoverflow
Solution 4 - VimchrboeschView Answer on Stackoverflow
Solution 5 - Vimuser3462225View Answer on Stackoverflow
Solution 6 - VimKostub DeshmukhView Answer on Stackoverflow
Solution 7 - VimRaminView Answer on Stackoverflow