nerdtree

preservimWTFPL长期未更新

Vim 编辑器里的文件树浏览插件,用侧边栏树形结构管理目录和文件,让写代码时不用离开编辑器就能快速切换、打开和操作文件。

A tree explorer plugin for vim.

暂无版本20,079star1,434fork同步于 2026-11-10 11:24 UTC

怎么上手

由 README 提炼,执行前请确认
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
硬件要求按 README 说明

README 未说明,仅需可运行 Vim 的环境,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Vim 编辑器的文件树浏览插件,让你在编辑器内直观浏览目录、快速打开文件

Vim 编辑器里的文件树浏览插件,用侧边栏树形结构管理目录和文件,让写代码时不用离开编辑器就能快速切换、打开和操作文件。

核心能力

  • 以树形结构可视化浏览复杂目录层级
  • 在树中直接打开文件进行阅读或编辑
  • 支持基础文件系统操作如新建删除移动复制
  • 提供内置 API 供自定义映射和函数扩展
  • 按 ? 键开启快速帮助查看全部映射与命令

容易踩的坑

插件本身不创建任何窗口外的快捷键,需自己在 vimrc 中用 nnoremap 绑定 不支持通过 scp 或 ftp 访问远程文件,远程文件需借助 Vim 自带的 netrw 用 Pathogen 安装后需手动执行 :helptags 生成文档标签

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    The NERDTree Vint

    Introduction

    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.

    NERDTree Screenshot

    Installation

    Use your favorite plugin manager to install this plugin. tpope/vim-pathogen, VundleVim/Vundle.vim, junegunn/vim-plug, and 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. 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.

    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.

    1. In the terminal,
      git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
      
    2. In your vimrc,
      call pathogen#infect()
      syntax on
      filetype plugin indent on
      
    3. Restart Vim, and run :helptags ~/.vim/bundle/nerdtree/doc/ or :Helptags.
    1. Install Vundle, according to its instructions.
    2. Add the following text to your vimrc.
      call vundle#begin()
        Plugin 'preservim/nerdtree'
      call vundle#end()
      
    3. Restart Vim, and run the :PluginInstall statement to install your plugins.
    1. Install Vim-Plug, according to its instructions.
    2. Add the following text to your vimrc.
    call plug#begin()
      Plug 'preservim/nerdtree'
    call plug#end()
    
    1. Restart Vim, and run the :PlugInstall statement to install your plugins.
    1. Install Dein, according to its instructions.
    2. Add the following text to your vimrc.
      call dein#begin()
        call dein#add('preservim/nerdtree')
      call dein#end()
      
    3. Restart Vim, and run the :call dein#install() statement to install your plugins.

    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/nerdtree
    vim -u NONE -c "helptags ~/.vim/pack/vendor/start/nerdtree/doc" -c q
    

    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.

    NERDTree Plugins

    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.

    If any others should be listed, mention them in an issue or pull request.

    Frequently Asked Questions

    In the answers to these questions, you will see code blocks that you can put in your vimrc file.

    How can I map a specific key or shortcut to open NERDTree?

    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.

    nnoremap <leader>n :NERDTreeFocus<CR>
    nnoremap <C-n> :NERDTree<CR>
    nnoremap <C-t> :NERDTreeToggle<CR>
    nnoremap <C-f> :NERDTreeFind<CR>
    

    How do I open NERDTree automatically when Vim starts?

    Each code block below is slightly different, as described in the " Comment lines.

    " Start NERDTree and leave the cursor in it.
    autocmd VimEnter * NERDTree
    

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

    " Start NERDTree when Vim is started without file arguments.
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
    

    " Start NERDTree. If a file is specified, move the cursor to its window.
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif
    

    " 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
    

    " 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 or a tab automatically when NERDTree is the last window?

    Because of the changes in how Vim handles its autocmd and layout locking quit 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!

    Vim9
    " 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() | call feedkeys(":quit\<CR>:\<BS>") | endif
    

    " Close the tab if NERDTree is the only window remaining in it.
    autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
    
    Vim8 or older
    " 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
    

    How can I prevent other buffers replacing NERDTree in its window?

    " If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
    autocmd BufEnter * if winnr() == winnr('h') && bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
        \ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
    

    Can I have the same NERDTree on every tab automatically?

    " Open the existing NERDTree on each new tab.
    autocmd BufWinEnter * 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>
    

    How can I change the default arrows?

    let g:NERDTreeDirArrowExpandable = '?'
    let g: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.

    How can I show lines of files?

    let g: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)
    

    Can NERDTree access remote files via scp or ftp?

    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 the scp:, 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(...)
        if a:0 == 0 || a:1 == ''
            NERDTree
        elseif filereadable(a:1)
            execute 'edit '.a:1
            return 0
        elseif a:1 =~? '^\(scp\|ftp\)://' " Add other protocols as needed.
            execute 'Vexplore '.a:1
        elseif isdirectory(a:1)
            execute 'NERDTree '.a:1
        endif
        return 1
    endfunction
    
    " Auto commands to handle OS commandline arguments
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc()==1 && !exists('s:std_in') | if <SID>OpenFileOrExplorer(argv()[0]) | wincmd p | enew | wincmd p | 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.
    cnoreabbrev e Edit