leoatchina的vim配置文件
This is leoatchina's vim config forked from spf13-vim:steve francia's vim distribution.I sincerely thank him for great job. To meet my needs,I have changed lots of settings and plugins.
__ _ _____ _
___ _ __ / _/ |___ / __ __(_)_ __ ___
/ __| '_ \| |_| | |_ \ _____\ \ / /| | '_ ` _ \
\__ \ |_) | _| |___) |_____|\ V / | | | | | | |
|___/ .__/|_| |_|____/ \_/ |_|_| |_| |_|
|_|
spf13對(duì)他自己作品的介紹
spf13-vim is a distribution of vim plugins and resources for Vim, Gvim and MacVim.
It is a good starting point for anyone intending to use VIM for development running equally well on Windows, Linux, *nix and Mac.
The distribution is completely customisable using a~/.vimrc.local
,~/.vimrc.bundles.local
, and~/.vimrc.before.local
Vim RC files.
背景
本人是生信工程師,主要使用的語文是python
,R
,perl
,shell
,經(jīng)常要ssh到遠(yuǎn)程服務(wù)器上寫代碼,因此學(xué)習(xí)了vim,后來發(fā)現(xiàn)了spf13-vim:steve francia's vim distribution,大大提高了寫代碼的效率样漆。但是,原配置仍然有很多插件和配置不符合我的需要,因此,fork后進(jìn)行了大量的修改.請(qǐng)?jiān)L問leoatchina的vim配置文件.由于本人水平所限,一定有很多錯(cuò)誤和bug,望各位指正.
注意使本配置文件后可能會(huì)影響vim運(yùn)行流暢度.
對(duì)使用者的要求
掌握vim的大部分操作,了解leader
,map
,hjkl
,d
,w
,s
,i
,u
,:
,\
等操作命令
配置文件
各配置文件執(zhí)行次序
-
.vimrc.before
# 參數(shù)配置文件 .vimrc.before.local
-
.vimrc.bundles
# 插件管理文件 .vimrc.bundles.local
-
.vimrc
# 最主要的配置文件,配色炼吴、快捷鍵清焕、顯示方式等參數(shù)都在這里設(shè)置 .vimrc.local
安裝
安裝本配置 需要 Git 1.7+ 和 Vim 7.3+(編譯時(shí)加入對(duì)lua和python的支持),部分插件如Nvim-R
,AsyncRun
,需要Vim8.0
如果要安裝neocomplete, 需要vim with lua.
Linux, *nix, Mac OSX 下的安裝
git clone https://github.com/leoatchina/spf13-vim-leoatchina.git
cd spf13-vim-leoatchina
bash bootstrap.sh
windows下的安裝
git clone https://github.com/leoatchina/spf13-vim-leoatchina.git
cd spf13-vim-leoatchina
點(diǎn)擊install.cmd
升級(jí)到最新版本
vim +BundleUpdate
或者在vim里直接 :BundleUpdate
一些功能
- 復(fù)制內(nèi)容直接放到系統(tǒng)剪貼本
- 顯示行號(hào),多種語法高亮
- 修改文檔后馬上生效
- Visual模式下用
>
,<
移動(dòng)文字不會(huì)取消選擇 - 不生成backup文件
- 關(guān)閉拼寫檢查
- 關(guān)閉聲音
- 關(guān)閉列光標(biāo)加亮
- 關(guān)閉行光標(biāo)加亮
- 允許折行
- 不代碼折疊
- 開啟實(shí)時(shí)搜索功能
- 顯示光標(biāo)當(dāng)前位置
- 高亮顯示搜索結(jié)果
- 折疊模式下翻頁(yè)的改進(jìn)
- 智能縮進(jìn)
- 沒有滾動(dòng)條
- 沒有菜單和工具條
- 總是顯示狀態(tài)欄
主要改動(dòng)
我在spf13的基礎(chǔ)上复濒,做了一些微小的工作
- 去除了一些比較冗余的插件,如wildfire坪创,并加入了自己喜歡的插件
- 修改了安裝代碼只祠,變成直接從clone的目錄中軟鏈接到用戶目錄下,不再支持XP
- 按自己習(xí)慣修改了大量插件的快捷鍵
- 去除了原來定義的一些函數(shù)
- 重點(diǎn)修改了代碼補(bǔ)全插件YouCompleteMe蝎毡、Neocomplete的配置和快捷鍵
- 去除了fork功能厚柳,僅保留before功能
- 增加對(duì)R和Markdown的支持,不過要在
~/.vimrc.before.local
里開啟 - 默認(rèn)不進(jìn)行代碼補(bǔ)全,要使用者在
~/.vimrc.before.local
里進(jìn)行配置,如我加入了對(duì)youcompletme
的配置,也可以使用neocomplte
和neocomplcache
- 我的
~/.vimrc.before.local
,可以看到有對(duì)python
,R
,markdown
的支持
let g:spf13_bundle_groups=['general', 'programming', 'python', 'youcompleteme','php', 'javascript', 'html','R','markdown','material']
基本快捷鍵
-
<leader>
鍵改為空格鍵,這個(gè)在鍵盤上最大的按鍵就有了更強(qiáng)的作用;<localleader>
改為\
,\
在R編寫調(diào)試時(shí)使用率比較高 -
~
作為進(jìn)入ex
模式的快捷鍵,Q
鍵map為<Nop>
-
F1
: 為:h
沐兵,方便啟動(dòng)幫助 -
F2
: 打開關(guān)閉代碼折疊 或<leader>wd
-
F3
: 打開關(guān)閉換行 或<leader>fd
-
F4
: 打開關(guān)閉搜索高亮 或<leader>hl
-
F5
: 運(yùn)行腳本(python别垮、perl、c等)或<leader>R
;Shift+F5
:運(yùn)行腳本并記錄時(shí)間;<leader>+F5
: AsyncRun -
F11
: 全屏切換,如果是windows下的gvim,要把本目錄下的gvim_fullscreen.dll
放到gvim
的安裝目錄下 -
F12
: 切換paste模式,或者<leader>tg
-
<leader>fc
:fixed confict markers -
<leader>fw
:對(duì)當(dāng)前光標(biāo)下文字進(jìn)行搜索 -
<leader>mk
:markdown調(diào)用chrome生成markdown preview - 在
Visual
模式下按.
為退出Visual
模式 - 標(biāo)簽頁(yè)控制
nnoremap <silent>- : tabprevious<CR>
nnoremap <silent>= : tabnext<CR>
nnoremap <leader>tf : tabfirst<CR>
nnoremap <Leader>tl : tablast<CR>
nnoremap <leader>tn : tabnew<CR>
nnoremap <Leader>ts : tabs<CR>
nnoremap <Leader>tp : tab split<CR>
nnoremap <Leader>te : tabe<SPACE>
nnoremap <Leader>tm : tabm<SPACE>
nnoremap <silent>_ : tabm -1<CR>
nnoremap <silent>+ : tabm +1<CR>
-
Ctrl+e
移到一行的結(jié)尾;Ctrl+y
移到一行的開頭 -
Ctrl+m
括號(hào)之間跳轉(zhuǎn) -
<leader>w
保存當(dāng)前文件;<leader>W
保存所有文件 -
<leader>q
關(guān)閉當(dāng)然文件;Q
為:qa
,不過給你反悔的機(jī)會(huì)不直接按下回車 - 復(fù)制粘貼等
" 設(shè)置快捷鍵將選中文本塊復(fù)制至系統(tǒng)剪貼板
vnoremap <leader>y "+y
nnoremap <leader>y "+y
nnoremap <leader>Y "+yg
nnoremap <leader>yy "+yy
" Yank from the cursor to the end of the line
nnoremap Y y$
" p and P for paste
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
- 其他一些快捷鍵
" buffer switch
nnoremap <leader>bn :bn<CR>
nnoremap <leader>bp :bp<CR>
" 定義快捷鍵保存當(dāng)前窗口內(nèi)容
nmap <Leader>w :w<CR>
nmap <Leader>W :wq!<CR>
" 定義快捷鍵保存所有窗口內(nèi)容并退出 vim
nmap <Leader>WQ :wa<CR>:q<CR>
" 定義快捷鍵關(guān)閉當(dāng)前窗口
nmap <Leader>q :q<CR>
" 不做任何保存扎谎,直接退出 vim
nmap <Leader>Q :qa!<CR>
" 設(shè)置分割頁(yè)面
nmap <Leader>- :split<Space>
nmap <leader>\ :vsplit<Space>
nmap <leader>= <C-W>=
"設(shè)置垂直高度減增
nmap <Leader>{ :resize -3<CR>
nmap <Leader>} :resize +3<CR>
"設(shè)置水平寬度減增
nmap <Leader>[ :vertical resize -3<CR>
nmap <Leader>] :vertical resize +3<CR>
"至左方的子窗口
nnoremap <Leader>H <C-W>H
"至右方的子窗口
nnoremap <Leader>L <C-W>L
"至上方的子窗口
nnoremap <Leader>K <C-W>K
"至下方的子窗口
nnoremap <Leader>J <C-W>J
" Visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
" Ctrl-m for switch between brackets
map <C-m> %
spf13設(shè)計(jì)了一系列巧妙的配置變量
碳想,在.vimrc.before.local
里寫入配置變量后烧董,可打開/關(guān)閉某些配置
如,關(guān)閉自動(dòng)cd到某個(gè)目錄
echo let g:spf13_no_autochdir = 1 >> ~/.vimrc.before.local
在 ~/.vimrc.before
文件里可以看到各個(gè)變量詳細(xì)說明
插件系統(tǒng)
強(qiáng)大的插件系統(tǒng)是spf13-vim的突出優(yōu)點(diǎn)移袍,通過這些插件解藻,將原版的vim的功能作了極大的豐富。讓界面更加美觀葡盗,操作更加方便螟左。在原有的基礎(chǔ)上,我加入了很多自己用的插件和對(duì)配置文件進(jìn)行了修改
spf13沒有選用pathongen作為插件管理器觅够,還是選用經(jīng)典的vundle
使用的插件
內(nèi)置兩套顏色主題
tyrannicaltoucan/vim-quantum
這是我在mac下的iterm2終端下使用的主題胶背,material配色,配合半透明效果看起來很酷炫喘先。
但要求終端支持
True Color
钳吟,如果不支持,效果會(huì)慘不忍睹窘拯。因此改成手動(dòng)開啟红且,方法:在~/.vimrc.before.local
里的g:spf13_bundle_groups
列表里加入material
altercation/vim-colors-solarized
經(jīng)典主題,默認(rèn)開啟涤姊,給一張官方的圖
還有三套內(nèi)置配色方案
ir_black
,molokai
,peaksea
,通過:color
命令開啟
scrooloose/nerdtree
在側(cè)邊顯示當(dāng)前目錄暇番,Toggle快捷鍵為Ctrl-N
或者<leader>nn
majutsushi/tagbar
顯示文檔結(jié)構(gòu),在python
,vim
里肯定有用思喊,要求在系統(tǒng)里安裝ctags
用Ctrl+T
or <leader>tt
切換在測(cè)邊顯示文檔結(jié)構(gòu).在bar窗口里按F1
調(diào)出幫助窗口
vim-voom/VOoM
另一個(gè)顯示文檔結(jié)構(gòu)的插件壁酬,和TagBar
邏輯不一樣,python
里肯定有用恨课,其他語言我還沒有測(cè)試出來舆乔。快捷鍵<leader>vo
打開 :Voom
命令;<leader>vt
為:VoomToggle
voom狀態(tài)切換
mbbill/undotree
undotree顧名思義,增強(qiáng)版的回退插件剂公,快捷鍵<leader>u
airline
漂亮的狀態(tài)欄,能夠顯示很多狀態(tài)希俩。
ywvim中文輸入法
ywvim
中文輸入法,直接在vim里內(nèi)置,無意中發(fā)現(xiàn)要和fcitx配合使用否則會(huì)有bug,在insert
模式下通過CTRL+@
或CTRL+\
開啟,CTRL+^
進(jìn)行配置.;
臨時(shí)英文輸入法;注意,默認(rèn)只輸入英文狀態(tài)的標(biāo)點(diǎn),而且首選是五筆
;z
臨時(shí)拼音;,.-=
上下翻頁(yè);
markdown
默認(rèn)開戶對(duì)markdown語言的高亮支持,如.vimrc.before.local
里指定markdown
支持,按<leadr>mk
調(diào)用chrome
打開markdown預(yù)覽,不過這個(gè)功能還要仔細(xì)測(cè)試過.
fugitive
對(duì)git的支持,具體可以看官方說明,不過我就設(shè)置了快捷鍵<leader>gi :Git<Space>
,操作體驗(yàn)接近終端下輸入git
命令
scrooloose/nerdcommenter
注釋插件,神器,直接上官方的快捷鍵,最常用的是<leader>c<space>
-
[count]<leader>cc
|NERDComComment|
Comment out the current line or text selected in visual mode. -
[count]<leader>cn
|NERDComNestedComment|
Same as <leader>cc but forces nesting. -
[count]<leader>c<space>
|NERDComToggleComment|
Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa. -
[count]<leader>cm
|NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters. -
[count]<leader>ci
|NERDComInvertComment|
Toggles the comment state of the selected line(s) individually. -
[count]<leader>cs
|NERDComSexyComment|
Comments out the selected lines with a pretty block formatted layout. -
[count]<leader>cy
|NERDComYankComment|
Same as <leader>cc except that the commented line(s) are yanked first. -
<leader>c$
|NERDComEOLComment|
Comments the current line from the cursor to the end of line. -
<leader>cA
|NERDComAppendComment|
Adds comment delimiters to the end of line and goes into insert mode between them. -
|NERDComInsertComment|
Adds comment delimiters at the current cursor position and inserts between. Disabled by default. -
<leader>ca
|NERDComAltDelim|
Switches to the alternative set of delimiters. -
[count]<leader>cl
[count]<leader>cb
|NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down the left side (<leader>cl
) or both sides (<leader>cb
). -
[count]<leader>cu
|NERDComUncommentLine|
Uncomments the selected line(s).
rking/ag.vim
Ag
是一個(gè)非常快的文件/文本搜索工具,通過<leader>ag
開遍文本搜索,<leader>af
文件搜索
Tabularize
自動(dòng)按特定的符號(hào)對(duì)齊,快捷鍵見.vimrc
里的配置文件
nmap <Leader>a& :Tabularize /&<CR>
vmap <Leader>a& :Tabularize /&<CR>
nmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
vmap <Leader>a= :Tabularize /^[^=]*\zs=<CR>
nmap <Leader>a=> :Tabularize /=><CR>
vmap <Leader>a=> :Tabularize /=><CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a:: :Tabularize /:\zs<CR>
vmap <Leader>a:: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a,, :Tabularize /,\zs<CR>
vmap <Leader>a,, :Tabularize /,\zs<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
sessionman
sessionmanager,<leader>sl
顯示session列表;<leader>ss
保存session;<leader>sc
關(guān)閉session
ctrlp
殺手級(jí)插件,引用網(wǎng)上的一段話對(duì)它的介紹
在 VIM 世界里诬留,有人是分窗口編輯文件的忠實(shí)擁護(hù)者斜纪,有人則是多文件 tab 頁(yè)的死忠骨灰粉。但無論哪種人文兑, 在一些大項(xiàng)目?jī)?nèi)進(jìn)行編輯工作時(shí),如果要快速打開 './lib/foo/bar/comm/base_utils.py' 這類藏在大山深處的文件腺劣,都需像剝粽子一樣绿贞,一層一層往下找,讓人頭疼橘原。
ctrlp.vim 則完美幫你解決了這個(gè)痛點(diǎn)籍铁,當(dāng)你想打開某個(gè)文件時(shí)涡上,只要按下 Ctrl + p 快捷鍵,輸入文件名拒名。 所有和這個(gè)文件名匹配的文件都會(huì)被按照優(yōu)先級(jí)列出來吩愧,按下 enter 或者 Ctrl + t 就可以在當(dāng)前 buffer 或者新 tab 頁(yè)打開你要的文件了。
網(wǎng)上找來的圖
ctrl+p
啟動(dòng)插件,<leader>fu
啟動(dòng)funksky函數(shù)查詢功能,在啟動(dòng)后,用Ctrl+f
,Ctrl+b
在不同模式中切換.
在文件列表中,Ctrl+k/j
或者方向鍵向上/下選擇文件,t
在新標(biāo)簽里打開文件.其他快捷鍵見ctrlp中文介紹
Pymode
python
用的插件,具有語法檢查,調(diào)試等功能.F9
: python語法檢查,S+F9
切換語法是否檢查.<leader>R
:運(yùn)行腳本;<leader>T
:track_point toggle
surround
給一段文字加上括號(hào)的插件增显,下面說明文字引用自vim中的殺手級(jí)別的插件:surround
Old text Command New text
"Hello *world!" ds" Hello world!
[123+4*56]/2 cs]) (123+456)/2
"Look ma, I'm *HTML!" cs"<q> <q>Look ma, I'm HTML!</q>
if *x>3 { ysW( if ( x>3 ) {
my $str = *whee!; vlllls' my $str = 'whee!';
<div>Yo!*</div> dst Yo!
<div>Yo!*</div> cst<p> <p>Yo!</p>
如上面代碼塊所示雁佳,添加替換時(shí)使用后半括號(hào))]},添加的括號(hào)和內(nèi)容間就沒有空格(如第2個(gè)示例)同云,反之會(huì)在內(nèi)容前后添加一個(gè)空格(如第4個(gè)實(shí)例)糖权。第6個(gè)示例中的t代表一對(duì)HTML或者xml tag。其他表示范圍的符號(hào):w代表word, W代表WORD(被空格分開的連續(xù)的字符竄)炸站,p代表paragraph星澳。
命令列表
Normal mode
-----------
ds - delete a surrounding
cs - change a surrounding
ys - add a surrounding
yS - add a surrounding and place the surrounded text on a new line + indent it
yss - add a surrounding to the whole line
ySs - add a surrounding to the whole line, place it on a new line + indent it
ySS - same as ySs
Visual mode
-----------
s - in visual mode, add a surrounding
S - in visual mode, add a surrounding but place text on new line + indent it
Insert mode "不建議使用
-----------
<CTRL-s> - in insert mode, add a surrounding
<CTRL-s><CTRL-s> - in insert mode, add a new line + surrounding + indent
<CTRL-g>s - same as <CTRL-s>
<CTRL-g>S - same as <CTRL-s><CTRL-s>
PIV
The most feature complete and up to date PHP Integration for Vim with proper support for PHP 5.3+ including latest syntax, functions, better fold support, etc.
PIV provides:
- PHP 5.3 support
- Auto generation of PHP Doc (,pd on (function, variable, class) definition line)
- Autocomplete of classes, functions, variables, constants and language keywords
- Better indenting
-
Full PHP documentation manual (hit K on any function for full docs)
Nvim-R
支持R語言的插件,需要Vim8.0+
并在.vimrc.before.local
里加入R
.通過<leader>rr
激活界面,<leader>rq
退出R程序
快捷鍵極多,請(qǐng)自行
:h nvim-r
查詢
EasyMotion
又一個(gè)殺手級(jí)別的插件
- 跳轉(zhuǎn)到當(dāng)前光標(biāo)前后,快捷鍵
<leader><leader>w
和<leader><leader>b
- 搜索跳轉(zhuǎn),
<leader><leader>s
,然后輸入要搜索的字母 - 行間/行內(nèi)級(jí)別跳轉(zhuǎn),
<leader><leader>
再hjkl
不解釋 - 重復(fù)上一次的動(dòng)作,
<leader><leader>.
- 還可以
<leader><leader>f
和<leader><leader>t
,不過不建議使用
代碼補(bǔ)全插件
- 用了三種補(bǔ)全插件,要在
~/.vimrc.before.local
里加入youcomplteme
或neocomplte
或neocomplcache
來激活安裝旱易。 - 基本快捷鍵統(tǒng)一為
Tab
禁偎、Shift-Tab
為向下
,向上
翻頁(yè)阀坏,ctrl-n/p
也能進(jìn)行翻頁(yè).enter
或Ctrl+k
激活補(bǔ)全如暖。ctrl+l
顯示各種實(shí)例可能
YouComplteMe
- 需要安裝一系列編譯用軟件
- 跳轉(zhuǎn)鍵,
Ctrl+f
跳轉(zhuǎn)到下一個(gè)待補(bǔ)全處全释,Ctrl+b
中轉(zhuǎn)到上一個(gè)待補(bǔ)全處装处。 - ?具體可參考Vim 自動(dòng)補(bǔ)全插件 YouCompleteMe 安裝與配置.
- 在安裝好各種編譯用的工具后
cd ~/.vim/bundle/YouCompleteMe
python2 install.py #可能僅支持python等不需要編譯的語言
neocomplete&&neocomplcache
- 這兩者是同一個(gè)作者?編寫,
neocomplte
需要lua
的支持