preservim / nerdtree

A tree explorer plugin for vim.
Do What The F*ck You Want To Public License
19.56k stars 1.44k forks source link

different files in different tabs with specific nerdtree #1420

Closed Elite-zx closed 3 months ago

Elite-zx commented 3 months ago

vim version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 1 2021 16:57:56)

vimrc:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Nerd Tree
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:NERDTreeWinPos = "left"
let NERDTreeShowHidden=0
let NERDTreeIgnore = ['\.pyc$', '__pycache__']
let g:NERDTreeWinSize=36
let g:NERDTreeChDirMode = 2
map <leader>nn :NERDTreeToggle<cr>
map <leader>nf :NERDTreeFind<cr>

" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * if &buftype != 'quickfix' && getcmdwintype() == '' | silent NERDTreeMirror | endif

" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif

" locate the current file in NERDTree
" autocmd BufWinEnter * NERDTreeFind

" Start NERDTree and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p

I have opened different files in different tabs, and these files are located in different directories. I would like NERDTree to be specific to each tab, displaying the directory of the file currently open in that tab. My current idea is to automatically execute NERDTreeFind when switching to a tab.

Currently, the behavior of NERDTree is such that when I switch tabs, the NERDTree interface remains the same and does not change.

rzvxa commented 3 months ago

Hi,

In the new tab if you want to create a new instance of NERDTree - as opposed to sharing the same instance - use the NERDTree command in place of NERDTreeToggle. It would force the NERDTree to create and use a new instance for that tab.

Optionally you can use NERDTreeMirror to mirror another instance. It allows you to select one if there are multiple instances in the current session.

There is also NERDTreeClose if you don't want to use NERDTreeToggle. use :help NERDTree to get our documentation or use :help NERDTree and press tab to get the list of commands and options available(and then you can select one to open the docs for it).