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

7

66

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.

Valdis answered 30/12, 2011 at 15:0 Comment(0)
L
30

Try adding

let NERDTreeMapOpenInTab='\r'

or

let NERDTreeMapOpenInTab='<ENTER>'

to your .vimrc.

Liebermann answered 30/12, 2011 at 21:8 Comment(6)
This also causes enter on a directory to open in a new tab.Valdis
how to traverse between file tabs in vim ?Kerk
It doesn't work with gvim x32 with my windows 7 x64. Any idea?Tough
There is this NerdTree + tabs plugin: github.com/jistr/vim-nerdtree-tabs could be useful.Beauty
While this technically answers the question, it renders directories inaccessible.Compost
@Valdis @Compost try this: let NERDTreeMapActivateNode='v' - you can use the v key to open/close directory nodes.Dogcart
H
99

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

Heavyset answered 2/7, 2018 at 18:31 Comment(2)
Nice. This closes NERDTree window. Is there anyway to keep it open.Glynisglynn
Found that 'T' opens in new tabGlynisglynn
L
30

Try adding

let NERDTreeMapOpenInTab='\r'

or

let NERDTreeMapOpenInTab='<ENTER>'

to your .vimrc.

Liebermann answered 30/12, 2011 at 21:8 Comment(6)
This also causes enter on a directory to open in a new tab.Valdis
how to traverse between file tabs in vim ?Kerk
It doesn't work with gvim x32 with my windows 7 x64. Any idea?Tough
There is this NerdTree + tabs plugin: github.com/jistr/vim-nerdtree-tabs could be useful.Beauty
While this technically answers the question, it renders directories inaccessible.Compost
@Valdis @Compost try this: let NERDTreeMapActivateNode='v' - you can use the v key to open/close directory nodes.Dogcart
S
12

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.

Spermatogonium answered 29/2, 2020 at 13:28 Comment(0)
T
10

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.

Twitter answered 1/10, 2014 at 8:11 Comment(1)
Tried, this, but didn't work: github.com/Nopik/vim-nerdtree-direnter/issues/1Evacuation
A
2

I use following map to do tab traverse :

nnoremap <C-l> gt
nnoremap <C-h> gT
Addict answered 2/12, 2015 at 2:29 Comment(1)
Also, would this not conflict the default mapping of moving between split panes? Because I have tried doing exactly this.Taipan
H
2

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
Highlands answered 1/2, 2017 at 1:29 Comment(1)
Will this be overwritten if I need to update the plugin? I assume it will if I delete then reinstall it.Slat
C
0

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

https://mcmap.net/q/297402/-remap-nerdtree-double-click-to-39-t-39

Champaigne answered 22/7, 2015 at 18:22 Comment(2)
Please, add the relevant information from your link into your answer.Furtive
Changing the source code is a very bad idea, especially since NerdTree offers a lot of options for configuration.Spermatogonium

© 2022 - 2024 — McMap. All rights reserved.