NERDTree是Vim的文件系统浏览器,使用此插件,用户可以直观地浏览复杂的目录层次结构,快速打开文件以进行读取或编辑,以及执行基本的文件系统操作。NERDTree源码在https://github.com/preservim/nerdtree 。
这里通过Vundle安装NERDTree,Vundle是Vim软件包的缩写,是Vim插件管理器。Vundle源码在https://github.com/VundleVim/Vundle.vim 。
安装Vundle:
(1). 执行如下命令:
mkdir -p ~/.vim/bundle git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
(2). 打开~/.vimrc,在此文件中添加内容如下:
set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " Keep Plugin commands between vundle#begin/end. " 安装其它插件 " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required
安装NERDTree:
(1). 执行如下命令:
git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
(2). 打开~/.vimrc,在语句call vundle#end()语句前添加内容如下:
Plugin 'preservim/nerdtree'
NERDTree常用快捷键:未说明默认是在命令行模式,命令前有”:”是在底行模式下
1. 通过vim打开一个文件后,在底行模式下输入”NERDTree”后回车进入NERDTree;
2. ctrl+w+h:光标focus左侧树形结构;
3. ctrl+w+l:光标focus右侧文件显示窗口;
4. ctrl+w+w:光标自动在左右侧窗口切换;
5. ctrl+w+r:移动当前窗口的布局位置;
6. o/go:在已有窗口中打开文件,跳到/不跳到该窗口;
7. o:如果光标定位在目录上,点击”o”则会展开或合拢该目录;
8. t/T:在新的Tab中打开文件,跳到/不跳到新Tab;
9. :tabc/:tabo:关闭当前的/关闭所有其它的Tab;
10. :tabp/:tabn:跳到前一个/跳到后一个Tab;
12. i/gi:split一个新窗口并打开选中文件,跳到/不跳到该窗口;
13. s/gs:vsplit一个新窗口并打开选中文件,跳到/不跳到该窗口;
14. x:合拢当前文件或目录的父目录;
15. P/p:跳到根结点/父结点;
16. C:将选中目录或选中文件的父目录设为根结点;
17. u/U:将当前根结点的父目录设为根结点,并合拢原根结点/展开原根结点;
18. r/R:递归刷新选中目录/根结点;
19. I:切换是否显示隐藏文件;
20. q:关闭NERDTree窗口。
打开NERDTree后界面如下:
完整的~/.vimrc文件内容如下:
" 安装Vundle: 参考:https://github.com/VundleVim/Vundle.vim " $ mkdir -p ~/.vim/bundle " $ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " Keep Plugin commands between vundle#begin/end. " 安装NERDTree " $ git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree Plugin 'preservim/nerdtree' " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " 语法高亮显示 syntax on " 缩进设置 set tabstop=8 set softtabstop=8 set shiftwidth=8 " C代码缩进 set cindent " 搜索结果高亮显示 set hlsearch " 解决中文字符显示乱码 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8
总结