- 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 :NERDTreeToggle. If 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.
- Android應(yīng)用程序開發(fā)與典型案例
- Visual C++串口通信開發(fā)入門與編程實踐
- C語言程序設(shè)計基礎(chǔ)與實驗指導(dǎo)
- Learning SAP Analytics Cloud
- 基于Java技術(shù)的Web應(yīng)用開發(fā)
- HTML5+CSS3網(wǎng)頁設(shè)計
- Android玩家必備
- OpenResty完全開發(fā)指南:構(gòu)建百萬級別并發(fā)的Web應(yīng)用
- ExtJS Web應(yīng)用程序開發(fā)指南第2版
- Emotional Intelligence for IT Professionals
- 遠(yuǎn)方:兩位持續(xù)創(chuàng)業(yè)者的點滴思考
- Python 快速入門(第3版)
- Getting Started with RethinkDB
- 零基礎(chǔ)入門學(xué)習(xí)C語言:帶你學(xué)C帶你飛
- Slick2D Game Development