GVim配置⼀个漂亮的NerdTree
GVim配置⼀个漂亮的NerdTree
  GVim使⽤也有⼀段时间了,有空写⼏个简单的教程帮助新⼿快速上⼿,定制⼀个个性化的编辑器把。以下是我的NerdTree效果展⽰。
NerdTree插件
NerdTree下载安装
  如果你安装了插件管理器的化安装就很简单了,如果没有安装使⽤任何插件管理器,那我建议你还是装⼀个,因为vim你会⽤到的插件挺多的,有个管理器很⽅便。
  将这句添加到vimrc中Plugin 'scrooloose/nerdtree',随后重启下vim然后命令模式下执⾏:BundleInstall(具体根据你装的插件,我装的是Bundle。)安装指令,完毕后最好再重启⼀次vim。
NerdTree配置
  ps: 以下我的配置仅供参考,具体配置请查阅github上的⽂档,因为随着作者版本的升级指令和功能可能会边。总之请灵活学习。
"""""""""""""""""""""""""""""""
"NerdTree setting
"""""""""""""""""""""""""""""""
set encoding=utf-8
set termencoding=utf-8
set fileencoding=chinese
set fileencodings=ucs-bom,utf-8,chinese
set langmenu=zh_CN.utf-8
language messages zh_cn.utf-8
"Show line number.
let g:NERDTreeShowlineNumber=1
"Show hide file.
let g:NERDTreeHidden=0
"Show Node model.
let NERDTreeDirArrows=1
"Delete help information at the top
let NERDTreeMinimalUI=1
let g:NERDTreeDirArrowExpandable = '|'
let g:NERDTreeDirArrowCollapsible = '/'
  简单解释下,前⾯⼏⾏将⼏个部分的字体设置为utf-8是为了防⽌再windows下乱码。是否显⽰⾏号这⾥配置为是,因为否的话左边⼀列每⾏⾸都会显⽰|符号,太多了不好看。配置为是反倒不会显⽰⾏号,且只有在⽂件夹左边才会显⽰|符号。剩下的配置根据注释意思好理解。⽂件召开或关闭很多⼈配置为三⾓符号,我试了下windows下需要折腾合适字体才能显⽰,我现在⽤的molokai字体是不⽀持的。其实我更喜欢的是键盘上的|和/符号,简单粗暴。
  另外我还建议加上这样⼀句配置,作⽤是当剩余的窗⼝都不是⽂件编辑窗⼝时,⾃动退出vim。就是你都不编辑⽂件了,还剩个NerdTree窗⼝在那⾥时⾃动退出GVim(执⾏:qa!)。
autocmd BufEnter * if 0 == len(filter(range(1, winnr('$')), 'empty(getbufvar(winbufnr(v:val), "&bt"))')) | qa! | endif
vim-devicons插件
  为了在NerdTree中显⽰图标需要装此插件,当然这个插件不光⽀持NerdTree,还⽀持vim-airline、CtrlP、powerline等。
vim-devicons下载安装
  插件安装都类似的,在vimrc中添加Plugin ‘ryanoasis/vim-devicons’
vim-devicons配置
""""""""""""""""""""""""""""""
"vim-devicons settings
""""""""""""""""""""""""""""""`
set encoding=UTF-8
"Can be enabled or disabled
let g:webdevicons_enable_nerdtree = 1
"whether or not to show the nerdtree brackets around flags
let g:webdevicons_conceal_nerdtree_brackets = 1
"adding to vim-airline's tabline
let g:webdevicons_enable_airline_tabline = 1
"adding to vim-airline's statusline
let g:webdevicons_enable_airline_statusline = 1
  根据注释很容易明⽩这些配置的作⽤,就是让这些插件⽀持特殊符号的显⽰。
  装完着两个插件还没结束。你装了NerdTree⽀持了⽬录树显⽰,devicons⽀持显⽰图标和⾼亮,最后还需要插件来管理显⽰的规则,即什么⽂件或⽂件夹应该显⽰什么样的图标和颜⾊。有了上⾯的安装基础,我下⾯讲的简略⼀点。
vim-nerdtree-syntax-highlight插件
  这个插件能根据⽂件类型显⽰不同的图标和颜⾊,⼤⼤美化了NerdTree显⽰效果。
vim-nerdtree-syntax-highlight下载安装
  vimrc⽂件中添加Plugin 'tiagofumo/vim-nerdtree-syntax-highlight'安装插件。
vim-nerdtree-syntax-highlight配置
""""""""""""""""""""""""""""""
"vim-nerdtree-syntax-highlight settings
""""""""""""""""""""""""""""""
"Highlight full name (not only icons). You need to add this if you don't have vim-devicons and want highlight.
let g:NERDTreeFileExtensionHighlightFullName = 1
let g:NERDTreeExactMatchHighlightFullName = 1
let g:NERDTreePatternMatchHighlightFullName = 1
"Highlight full name (not only icons). You need to add this if you don't have vim-devicons and want highlight.
let g:NERDTreeHighlightFolders = 1
"highlights the folder name
let g:NERDTreeHighlightFoldersFullName = 1
"you can add these colors to your .vimrc to help customizing
let s:brown = "905532"
let s:aqua =  "3AFFDB"
let s:blue = "689FB6"
好看的留言let s:darkBlue = "44788E"
let s:purple = "834F79"
let s:lightPurple = "834F79"
let s:red = "AE403F"
let s:beige = "F5C06F"
let s:yellow = "F09F17"
let s:orange = "D4843E"
let s:darkOrange = "F16529"
let s:pink = "CB6F6F"
let s:salmon = "EE6E73"
let s:green = "8FAA54"
let s:Turquoise = "40E0D0"
let s:lightGreen = "31B53E"
let s:white = "FFFFFF"
let s:rspec_red = "FE405F"
let s:git_orange = "F54D27"
let s:gray = "808A87"
let g:NERDTreeExtensionHighlightColor = {} " this line is needed to avoid error
let g:NERDTreeExtensionHighlightColor['o'] = s:gray " sets the color of o files to blue
let g:NERDTreeExtensionHighlightColor['h'] = s:blue " sets the color of h files to blue
let g:NERDTreeExtensionHighlightColor['c'] = s:green " sets the color of c files to blue
let g:NERDTreeExtensionHighlightColor['cpp'] = s:green " sets the color of cpp files to blue
let g:NERDTreeExtensionHighlightColor['c++'] = s:green " sets the color of c++ files to blue
  这个插件有⼀些默认的颜⾊显⽰规则,但是⽀持⾃定义,你可以制定颜⾊值和哪些后缀的⽂件显⽰什么颜⾊,没有指定的就还是按默认规则,如果默认也没指定那就时⽩⾊。
  *ps:这⾥有个坑。你如果看过github上作者给出的配置,你会发现作者在每句指定⽂件类型颜⾊的配置前都加了⼀句let
g:NERDTreeExtensionHighlightColor = {},在Windows下这么配置只有最后⼀句指定⽂件类型的颜⾊能⽣效,后来我只保留了第⼀句就没问题了。
 &ems;完了吗?还没有!我再推荐⼀个插件,对于编写github的⼈有帮助。这个插件能⽤图标在NerdTree⾥(vim-gitgutter是在编辑区⾥按⾏标识)标识出哪些⽬录下的哪些⽂件做了何种修改,⽐如增加、删除、新创建等。
nerdtree-git-plugin插件
  和github上传的代码作对⽐,在NerdTree⽬录中⽤图标标识出⽂件和⽂件夹做了何种修改的插件。
nerdtree-git-plugin下载安装
  在vimrc中添加Plugin 'Xuyuanp/nerdtree-git-plugin'安装此插件。
nerdtree-git-plugint配置
""""""""""""""""""""""""""""""
"nerdtree-git-plugin settings
""""""""""""""""""""""""""""""
let g:NERDTreeShowIgnoredStatus = 1
let g:NERDTreeIndicatorMapCustom = {
\ "Modified"  : "✹",
\ "Staged"    : "✚",
\ "Untracked" : "✭",
\ "Renamed"  : "➜",
\ "Unmerged"  : "═",
\ "Deleted"  : "✖",
\ "Dirty"    : "✗",
\ "Clean"    : "✔ ",
\ 'Ignored'  : '☒',
\ "Unknown"  : "?"
\ }
  你可以修改为⾃⼰喜欢的符号,但是要注意得是你当前所⽤字体所⽀持显⽰的,不是啥符号都⾏。
结语
  这次真的写完了?其实还⽤过其他的⼀些插件这⾥就不写了,毕竟⽼了,坐久了不舒服。相信捣⿎,猛操作⼀番后的你也拥有了⼜给好看的NerdTree界⾯。如有疑问欢迎留⾔。