官术网_书友最值得收藏!

  • Mastering Vim
  • Ruslan Osipov
  • 361字
  • 2021-06-10 18:51:30

Plugin spotlight – NERDTree

NERDTree is a handy plugin that emulates modern IDE behavior by displaying a file tree in a split buffer to the side of the screen. NERDTree is available from https://github.com/scrooloose/nerdtree (see Installing Plugins earlier in this chapter for installation instructions). 

Once installed, you can invoke NERDTree by typing the following:

:NERDTree

A list of files in a directory will show up:

Use h, j, k, and l or the arrow keys to navigate the file structure, and Enter or o to open the file. There are multiple useful shortcuts, and Shift ? brings up a handy cheat sheet.

A notable feature is bookmark support, which allows you to bookmark a directory (when placing the cursor over it in NERDTree) by executing :Bookmark. Press B when in a NERDTree window to display bookmarks at the top of the window.

In the following screenshot, you can see the bookmarks I have for code that supports chapters of this book (the Chapter01/ and Chapter02/ directories):

You can choose to always display bookmarks in a NERDTree window by setting the NERDTreeShowBookmarks option in your .vimrc file:

let NERDTreeShowBookmarks = 1  " Display bookmarks on startup.

You can bring NERDTree up or hide it by executing :NERDTreeToggleIf you're interested in having NERDTree up every time you're editing, you might want to add the following to your .vimrc file:

autocmd VimEnter * NERDTree  " Enable NERDTree on Vim startup.

Something I personally found really useful is to close the NERDTree window automatically when it's the last open window. I have the following in my .vimrc file:

" Autoclose NERDTree if it's the only open window left.
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") &&
\ b:NERDTree.isTabTree()) | q | endif

These days, I rarely find myself using NERDTree. Before switching to Vim, I often relied on having a project outline in the view when I worked. In my early days of learning Vim, NERDTree was a lifesaver. Vim changed the way I work and having a file outline always on became distracting, so eventually I moved back to using Netrw.

主站蜘蛛池模板: 江西省| 信阳市| 河南省| 奉新县| 禹城市| 内乡县| 南京市| 喀喇沁旗| 万全县| 泽库县| 合江县| 光泽县| 东乌| 慈利县| 阿鲁科尔沁旗| 呼和浩特市| 锡林郭勒盟| 盐亭县| 云阳县| 句容市| 石泉县| 溧水县| 彭泽县| 广汉市| 丁青县| 延长县| 邹平县| 广安市| 霍城县| 繁峙县| 仁寿县| 固原市| 灵丘县| 陆良县| 祥云县| 绿春县| 平塘县| 名山县| 叙永县| 上犹县| 嘉鱼县|