NERDTree是Vim的文件系統(tǒng)瀏覽器,使用此插件,用戶可以直觀地瀏覽復(fù)雜的目錄層次結(jié)構(gòu),快速打開(kāi)文件以進(jìn)行讀取或編輯,以及執(zhí)行基本的文件系統(tǒng)操作。NERDTree源碼在https://github.com/preservim/nerdtree 。
這里通過(guò)Vundle安裝NERDTree,Vundle是Vim軟件包的縮寫(xiě),是Vim插件管理器。Vundle源碼在https://github.com/VundleVim/Vundle.vim 。
安裝Vundle:
(1). 執(zhí)行如下命令:
mkdir -p ~/.vim/bundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
(2). 打開(kāi)~/.vimrc,在此文件中添加內(nèi)容如下:
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). 執(zhí)行如下命令:
git clone https://github.com/preservim/nerdtree.git ~/.vim/bundle/nerdtree
(2). 打開(kāi)~/.vimrc,在語(yǔ)句call vundle#end()語(yǔ)句前添加內(nèi)容如下:
Plugin 'preservim/nerdtree'
NERDTree常用快捷鍵:未說(shuō)明默認(rèn)是在命令行模式,命令前有”:”是在底行模式下
1. 通過(guò)vim打開(kāi)一個(gè)文件后,在底行模式下輸入”NERDTree”后回車進(jìn)入NERDTree;
2. ctrl+w+h:光標(biāo)focus左側(cè)樹(shù)形結(jié)構(gòu);
3. ctrl+w+l:光標(biāo)focus右側(cè)文件顯示窗口;
4. ctrl+w+w:光標(biāo)自動(dòng)在左右側(cè)窗口切換;
5. ctrl+w+r:移動(dòng)當(dāng)前窗口的布局位置;
6. o/go:在已有窗口中打開(kāi)文件,跳到/不跳到該窗口;
7. o:如果光標(biāo)定位在目錄上,點(diǎn)擊”o”則會(huì)展開(kāi)或合攏該目錄;
8. t/T:在新的Tab中打開(kāi)文件,跳到/不跳到新Tab;
9. :tabc/:tabo:關(guān)閉當(dāng)前的/關(guān)閉所有其它的Tab;
10. :tabp/:tabn:跳到前一個(gè)/跳到后一個(gè)Tab;
12. i/gi:split一個(gè)新窗口并打開(kāi)選中文件,跳到/不跳到該窗口;
13. s/gs:vsplit一個(gè)新窗口并打開(kāi)選中文件,跳到/不跳到該窗口;
14. x:合攏當(dāng)前文件或目錄的父目錄;
15. P/p:跳到根結(jié)點(diǎn)/父結(jié)點(diǎn);
16. C:將選中目錄或選中文件的父目錄設(shè)為根結(jié)點(diǎn);
17. u/U:將當(dāng)前根結(jié)點(diǎn)的父目錄設(shè)為根結(jié)點(diǎn),并合攏原根結(jié)點(diǎn)/展開(kāi)原根結(jié)點(diǎn);
18. r/R:遞歸刷新選中目錄/根結(jié)點(diǎn);
19. I:切換是否顯示隱藏文件;
20. q:關(guān)閉NERDTree窗口。
打開(kāi)NERDTree后界面如下:
完整的~/.vimrc文件內(nèi)容如下:
" 安裝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
" 語(yǔ)法高亮顯示
syntax on
" 縮進(jìn)設(shè)置
set tabstop=8
set softtabstop=8
set shiftwidth=8
" C代碼縮進(jìn)
set cindent
" 搜索結(jié)果高亮顯示
set hlsearch
" 解決中文字符顯示亂碼
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
總結(jié)
到此這篇關(guān)于Ubuntu上Vim安裝NERDTree插件操作步驟的文章就介紹到這了,更多相關(guān)Vim安裝NERDTree插件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!