- Notifications
You must be signed in to change notification settings - Fork1.4k
A tree explorer plugin for vim.
License
preservim/nerdtree
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The NERDTree is a file system explorer for the Vim editor. Using this plugin, users can visually browse complex directory hierarchies, quickly open files for reading or editing, and perform basic file system operations.
Use your favorite plugin manager to install this plugin.tpope/vim-pathogen,VundleVim/Vundle.vim,junegunn/vim-plug, andShougo/dein.vim are some of the more popular ones. A lengthy discussion of these and other managers can be found onvi.stackexchange.com. Basic instructions are provided below, but pleasebe sure to read, understand, and follow all the safety rules that come with yourpower tools plugin manager.
If you have no favorite, or want to manage your plugins without 3rd-party dependencies, consider using Vim 8+ packages, as described in Greg Hurrell's excellent Youtube video:Vim screencast #75: Plugin managers.
Pathogen
Pathogen is more of a runtime path manager than a plugin manager. You must clone the plugins' repositories yourself to a specific location, and Pathogen makes sure they are available in Vim.- In the terminal,
git clone https://github.com/preservim/nerdtree.git~/.vim/bundle/nerdtree
- In your
vimrc
,callpathogen#infect()syntaxonfiletypepluginindenton
- Restart Vim, and run
:helptags ~/.vim/bundle/nerdtree/doc/
or:Helptags
.
Vundle
- Install Vundle, according to its instructions.
- Add the following text to your
vimrc
.callvundle#begin()Plugin'preservim/nerdtree'callvundle#end()
- Restart Vim, and run the
:PluginInstall
statement to install your plugins.
Vim-Plug
- Install Vim-Plug, according to its instructions.
- Add the following text to your
vimrc
.
callplug#begin() Plug'preservim/nerdtree'callplug#end()
- Restart Vim, and run the
:PlugInstall
statement to install your plugins.
Dein
- Install Dein, according to its instructions.
- Add the following text to your
vimrc
.calldein#begin()calldein#add('preservim/nerdtree')calldein#end()
- Restart Vim, and run the
:call dein#install()
statement to install your plugins.
Vim 8+ packages
If you are using Vim version 8 or higher you can use its built-in package management; see:help packages
for more information. Just run these commands in your terminal:
git clone https://github.com/preservim/nerdtree.git~/.vim/pack/vendor/start/nerdtreevim -u NONE -c"helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q
After installing NERDTree, the best way to learn it is to turn on the Quick Help. Open NERDTree with the:NERDTree
command, and press?
to turn on the Quick Help, which will show you all the mappings and commands available in the NERDTree. Of course, your most complete source of information is the documentation::help NERDTree
.
NERDTree can be extended with custom mappings and functions using its built-in API. The details of this API are described in the included documentation. Several plugins have been written, and are available on Github for installation like any other plugin. The plugins in this list are maintained (or not) by their respective owners, and certain combinations may be incompatible.
- Xuyuanp/nerdtree-git-plugin: Shows Git status flags for files and folders in NERDTree.
- ryanoasis/vim-devicons: Adds filetype-specific icons to NERDTree files and folders,
- tiagofumo/vim-nerdtree-syntax-highlight: Adds syntax highlighting to NERDTree based on filetype.
- scrooloose/nerdtree-project-plugin: Saves and restores the state of the NERDTree between sessions.
- PhilRunninger/nerdtree-buffer-ops: 1) Highlights open files in a different color. 2) Closes a buffer directly from NERDTree.
- PhilRunninger/nerdtree-visual-selection: Enables NERDTree to open, delete, move, or copy multiple Visually-selected files at once.
If any others should be listed, mention them in an issue or pull request.
In the answers to these questions, you will see code blocks that you can put in yourvimrc
file.
NERDTree doesn't create any shortcuts outside of the NERDTree window, so as not to overwrite any of your other shortcuts. Use thennoremap
command in yourvimrc
. You, of course, have many keys and NERDTree commands to choose from. Here are but a few examples.
nnoremap<leader>n :NERDTreeFocus<CR>nnoremap<C-n>:NERDTree<CR>nnoremap<C-t>:NERDTreeToggle<CR>nnoremap<C-f>:NERDTreeFind<CR>
Each code block below is slightly different, as described in the" Comment lines
.
" Start NERDTree and leave the cursor in it.autocmdVimEnter* NERDTree
" Start NERDTree and put the cursor back in the other window.autocmdVimEnter* NERDTree |wincmdp
" Start NERDTree when Vim is started without file arguments.autocmdStdinReadPre*lets:std_in=1autocmdVimEnter*ifargc()==0&&!exists('s:std_in') | NERDTree |endif
" Start NERDTree. If a file is specified, move the cursor to its window.autocmdStdinReadPre*lets:std_in=1autocmdVimEnter* NERDTree |ifargc() >0||exists("s:std_in") |wincmdp |endif
" Start NERDTree, unless a file or session is specified, eg. vim -S session_file.vim.autocmdStdinReadPre*lets:std_in=1autocmdVimEnter*ifargc()==0&&!exists('s:std_in')&&v:this_session=='' | NERDTree |endif
" Start NERDTree when Vim starts with a directory argument.autocmdStdinReadPre*lets:std_in=1autocmdVimEnter*ifargc()==1&&isdirectory(argv()[0])&&!exists('s:std_in') |\execute'NERDTree'argv()[0] |wincmdp |enew |execute'cd'.argv()[0] |endif
Because of the changes in how Vim handles itsautocmd
and layout lockingquit
command is no longer available in Vim9 auto commands, Depending on which version you're running select one of these solutions.
NeoVim users should be able to choose either one of them!
" Exit Vim if NERDTree is the only window remaining in the only tab.autocmdBufEnter*iftabpagenr('$')==1&&winnr('$')==1&&exists('b:NERDTree')&&b:NERDTree.isTabTree() |callfeedkeys(":quit\<CR>:\<BS>") |endif
" Close the tab if NERDTree is the only window remaining in it.autocmdBufEnter*ifwinnr('$')==1&&exists('b:NERDTree')&&b:NERDTree.isTabTree() |callfeedkeys(":quit\<CR>:\<BS>") |endif
" Exit Vim if NERDTree is the only window remaining in the only tab.autocmdBufEnter*iftabpagenr('$')==1&&winnr('$')==1&&exists('b:NERDTree')&&b:NERDTree.isTabTree() |quit |endif
" Close the tab if NERDTree is the only window remaining in it.autocmdBufEnter*ifwinnr('$')==1&&exists('b:NERDTree')&&b:NERDTree.isTabTree() |quit |endif
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.autocmdBufEnter*ifwinnr()==winnr('h')&&bufname('#')=~'NERD_tree_\d\+'&&bufname('%')!~'NERD_tree_\d\+'&&winnr('$') >1 |\letbuf=bufnr() |buffer# |execute"normal!\<C-W>w" |execute'buffer'.buf |endif
" Open the existing NERDTree on each new tab.autocmdBufWinEnter*if &buftype!='quickfix'&&getcmdwintype()=='' |silent NERDTreeMirror |endif
or change your NERDTree-launching shortcut key like so:
" Mirror the NERDTree before showing it. This makes it the same on all tabs.nnoremap<C-n>:NERDTreeMirror<CR>:NERDTreeFocus<CR>
letg:NERDTreeDirArrowExpandable='?'letg:NERDTreeDirArrowCollapsible='?'
The preceding values are the non-Windows default arrow symbols. Setting these variables to empty strings will remove the arrows completely and shift the entire tree two character positions to the left. See:h NERDTreeDirArrowExpandable
for more details.
letg:NERDTreeFileLines=1
Lines in the file are displayed as shown below.
</pack/packer/start/nerdtree/▸ autoload/▸ doc/▸ lib/▸ nerdtree_plugin/▸ plugin/▸ syntax/ _config.yml (1) CHANGELOG.md (307) LICENCE (13) README.markdown (234) screenshot.png (219)
Short answer: No, and there are no plans to add that functionality. However, Vim ships with a plugin that does just that. It's called netrw, and by adding the following lines to your.vimrc
, you can use it to open files over thescp:
,ftp:
, or other protocols, while still using NERDTree for all local files. The function seamlessly makes the decision to open NERDTree or netrw, and other supported protocols can be added to the regular expression.
" Function to open the file or NERDTree or netrw." Returns: 1 if either file explorer was opened; otherwise, 0.function!s:OpenFileOrExplorer(...)ifa:0==0||a:1=='' NERDTreeelseiffilereadable(a:1)execute'edit'.a:1return0elseifa:1=~?'^\(scp\|ftp\)://'" Add other protocols as needed.execute'Vexplore'.a:1elseifisdirectory(a:1)execute'NERDTree'.a:1endifreturn1endfunction" Auto commands to handle OS commandline argumentsautocmdStdinReadPre*lets:std_in=1autocmdVimEnter*ifargc()==1&&!exists('s:std_in') |if<SID>OpenFileOrExplorer(argv()[0]) |wincmdp |enew |wincmdp |endif |endif" Command to call the OpenFileOrExplorer function.command! -n=? -complete=file-bar Edit :call<SID>OpenFileOrExplorer('<args>')" Command-mode abbreviation to replace the :edit Vim command.cnoreabbreve Edit
About
A tree explorer plugin for vim.