1
0
Fork 0
mirror of synced 2024-11-14 05:08:56 -05:00
ultimate-vim/sources_non_forked/nerdtree/README.markdown

186 lines
8.2 KiB
Markdown
Raw Normal View History

2021-06-30 13:00:07 -04:00
# The NERDTree [![Vint](https://github.com/preservim/nerdtree/workflows/Vint/badge.svg)](https://github.com/preservim/nerdtree/actions?workflow=Vint)
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
## Introduction
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
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.
2012-08-16 23:41:25 -04:00
2020-01-07 07:45:07 -05:00
![NERDTree Screenshot](https://github.com/preservim/nerdtree/raw/master/screenshot.png)
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
## Installation
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
Use your favorite plugin manager to install this plugin. [tpope/vim-pathogen](https://github.com/tpope/vim-pathogen), [VundleVim/Vundle.vim](https://github.com/VundleVim/Vundle.vim), [junegunn/vim-plug](https://github.com/junegunn/vim-plug), and [Shougo/dein.vim](https://github.com/Shougo/dein.vim) are some of the more popular ones. A lengthy discussion of these and other managers can be found on [vi.stackexchange.com](https://vi.stackexchange.com/questions/388/what-is-the-difference-between-the-vim-plugin-managers). Basic instructions are provided below, but please **be sure to read, understand, and follow all the safety rules that come with your ~~power tools~~ plugin manager.**
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
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](https://www.youtube.com/watch?v=X2_R3uxDN6g).
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
<details>
<summary>Pathogen</summary>
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.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
1. In the terminal,
```bash
git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
```
1. In your `vimrc`,
```vim
call pathogen#infect()
syntax on
filetype plugin indent on
```
1. Restart Vim, and run `:helptags ~/.vim/bundle/nerdtree/doc/` or `:Helptags`.
</details>
2019-11-16 10:28:42 -05:00
2021-06-30 13:00:07 -04:00
<details>
<summary>Vundle</summary>
2019-11-16 10:28:42 -05:00
2021-06-30 13:00:07 -04:00
1. Install Vundle, according to its instructions.
1. Add the following text to your `vimrc`.
```vim
call vundle#begin()
Plugin 'preservim/nerdtree'
call vundle#end()
```
1. Restart Vim, and run the `:PluginInstall` statement to install your plugins.
</details>
2019-11-16 10:28:42 -05:00
2021-06-30 13:00:07 -04:00
<details>
<summary>Vim-Plug</summary>
2019-11-16 10:28:42 -05:00
2021-06-30 13:00:07 -04:00
1. Install Vim-Plug, according to its instructions.
1. Add the following text to your `vimrc`.
2019-11-16 10:28:42 -05:00
```vim
call plug#begin()
2021-06-30 13:00:07 -04:00
Plug 'preservim/nerdtree'
2019-11-16 10:28:42 -05:00
call plug#end()
```
2021-06-30 13:00:07 -04:00
1. Restart Vim, and run the `:PlugInstall` statement to install your plugins.
</details>
2015-12-08 08:20:04 -05:00
2021-06-30 13:00:07 -04:00
<details>
<summary>Dein</summary>
1. Install Dein, according to its instructions.
1. Add the following text to your `vimrc`.
```vim
call dein#begin()
call dein#add('preservim/nerdtree')
call dein#end()
```
1. Restart Vim, and run the `:call dein#install()` statement to install your plugins.
</details>
<details>
<summary>Vim 8+ packages</summary>
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:
2020-04-25 21:56:16 -04:00
2019-11-16 10:28:42 -05:00
```bash
2021-06-30 13:00:07 -04:00
git clone https://github.com/preservim/nerdtree.git ~/.vim/pack/vendor/start/nerdtree
vim -u NONE -c "helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q
2019-11-16 10:28:42 -05:00
```
2021-06-30 13:00:07 -04:00
</details>
2015-12-08 08:20:04 -05:00
2021-06-30 13:00:07 -04:00
## Getting Started
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`.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
## NERDTree Plugins
NERDTree can be extended with custom mappings and functions using its built-in API. The details of this API and 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.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
* [Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin): Shows Git status flags for files and folders in NERDTree.
* [ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons): Adds filetype-specific icons to NERDTree files and folders,
* [tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight): Adds syntax highlighting to NERDTree based on filetype.
* [scrooloose/nerdtree-project-plugin](https://github.com/scrooloose/nerdtree-project-plugin): Saves and restores the state of the NERDTree between sessions.
* [PhilRunninger/nerdtree-buffer-ops](https://github.com/PhilRunninger/nerdtree-buffer-ops): 1) Highlights open files in a different color. 2) Closes a buffer directly from NERDTree.
* [PhilRunninger/nerdtree-visual-selection](https://github.com/PhilRunninger/nerdtree-visual-selection): Enables NERDTree to open, delete, move, or copy multiple Visually-selected files at once.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
If any others should be listed, mention them in an issue or pull request.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
## Frequently Asked Questions
2014-07-02 07:18:18 -04:00
2021-06-30 13:00:07 -04:00
In the answers to these questions, you will see code blocks that you can put in your `vimrc` file.
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
### How can I map a specific key or shortcut to open NERDTree?
2021-06-30 13:00:07 -04:00
NERDTree doesn't create any shortcuts outside of the NERDTree window, so as not to overwrite any of your other shortcuts. Use the `nnoremap` command in your `vimrc`. You, of course, have many keys and NERDTree commands to choose from. Here are but a few examples.
2019-11-16 10:28:42 -05:00
```vim
2021-06-30 13:00:07 -04:00
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>
2019-11-16 10:28:42 -05:00
```
2021-06-30 13:00:07 -04:00
### How do I open NERDTree automatically when Vim starts?
Each code block below is slightly different, as described in the `" Comment lines`.
2015-12-08 08:20:04 -05:00
2021-06-30 13:00:07 -04:00
```vim
" Start NERDTree and leave the cursor in it.
autocmd VimEnter * NERDTree
```
---
```vim
" Start NERDTree and put the cursor back in the other window.
autocmd VimEnter * NERDTree | wincmd p
```
2016-10-02 07:37:21 -04:00
---
2019-11-16 10:28:42 -05:00
```vim
2021-06-30 13:00:07 -04:00
" Start NERDTree when Vim is started without file arguments.
2019-11-16 10:28:42 -05:00
autocmd StdinReadPre * let s:std_in=1
2021-06-30 13:00:07 -04:00
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
2019-11-16 10:28:42 -05:00
```
---
```vim
2021-06-30 13:00:07 -04:00
" Start NERDTree. If a file is specified, move the cursor to its window.
2019-11-16 10:28:42 -05:00
autocmd StdinReadPre * let s:std_in=1
2021-06-30 13:00:07 -04:00
autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
```
---
```vim
" Start NERDTree, unless a file or session is specified, eg. vim -S session_file.vim.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') && v:this_session == '' | NERDTree | endif
2019-11-16 10:28:42 -05:00
```
2016-05-14 07:57:54 -04:00
---
2021-06-30 13:00:07 -04:00
```vim
" Start NERDTree when Vim starts with a directory argument.
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
\ execute 'NERDTree' argv()[0] | wincmd p | enew | execute 'cd '.argv()[0] | endif
```
### How can I close Vim automatically when NERDTree is the last window?
2012-08-16 23:41:25 -04:00
2019-11-16 10:28:42 -05:00
```vim
2021-06-30 13:00:07 -04:00
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
\ quit | endif
2019-11-16 10:28:42 -05:00
```
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
### How can I prevent other buffers replacing NERDTree in its window?
2012-08-16 23:41:25 -04:00
2019-11-16 10:28:42 -05:00
```vim
2021-06-30 13:00:07 -04:00
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
2019-11-16 10:28:42 -05:00
```
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
### Can I have the same NERDTree on every tab automatically?
2012-08-16 23:41:25 -04:00
2021-06-30 13:00:07 -04:00
```vim
" Open the existing NERDTree on each new tab.
autocmd BufWinEnter * silent NERDTreeMirror
```
or change your NERDTree-launching shortcut key like so:
```vim
" Mirror the NERDTree before showing it. This makes it the same on all tabs.
nnoremap <C-n> :NERDTreeMirror<CR>:NERDTreeFocus<CR>
```
2015-12-08 08:20:04 -05:00
2021-06-30 13:00:07 -04:00
### How can I change the default arrows?
2015-12-08 08:20:04 -05:00
2019-11-16 10:28:42 -05:00
```vim
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
```
2021-06-30 13:00:07 -04:00
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.