在這篇中, 會(huì)列舉各種實(shí)用的插件, 包括他們的安裝, 配置及使用方法
注意: 不是本部分的所有插件都是你需要裝的, 如果盲目安裝插件只會(huì)導(dǎo)致你 vim 功能混亂, 速度底下, 所以適時(shí)整理真正需要的插件, 禁用或清除掉不常用的插件才是正確使用方法.
本系列教程共分為以下五個(gè)部分:
神級(jí)編輯器 Vim 使用-基礎(chǔ)篇
神級(jí)編輯器 Vim 使用-操作篇
神級(jí)編輯器 Vim 使用-插件篇
神級(jí)編輯器 Vim 使用-正則操作篇
神級(jí)編輯器 Vim 使用-最后
vim-plug
是 vim 下的插件管理器, 可以幫我們統(tǒng)一管理后續(xù)的所有插件, 后續(xù)的安裝插件全部由此工具完成
類(lèi)似的插件管理工具還有 Vundle , 相較而言 vim-plug
支持異步且效率非常高, 具體選擇交由讀者自己
安裝終端中輸入如下命令
1 2 curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw./junegunn/vim-plug/master/plug.vim
基礎(chǔ)命令
PlugInstall
: 安裝插件
PlugUpdate
: 更新所有插件
PlugUpgrade
: 更新插件本身
PlugClean
: 刪除插件, 把安裝插件對(duì)應(yīng)行刪除, 然后執(zhí)行這個(gè)命令即可
安裝插件流程安裝完 vim-plug
之后, 我們就可以使用其為我們服務(wù)安裝插件了, 我們只需要在 call plug#begin(~/.vim/plugged)
與 call plug#end()
中指明我們需要的第三方插件即可, 如下:
1 2 3 4 5 6 7 8 call plug#begin('~/.vim/plugged') Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " 模糊搜索 Plug 'junegunn/fzf.vim' " 模糊搜索 Plug 'embear/vim-localvimrc' Plug 'ycm-core/YouCompleteMe' " 補(bǔ)全插件 call plug#end()
后續(xù)的所有插件除非特別說(shuō)明, 否則都按照 Plug 'PlugName'
的方式進(jìn)行安裝
自動(dòng)格式化管理插件, 可根據(jù)不同文件類(lèi)型使用不同的格式化工具
安裝1 Plug 'Chiel92/vim-autoformat'
配置1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 "***************** vim-autoformat ********************** let g:autoformat_verbosemode=0 "詳細(xì)模式 let g:autoformat_autoindent = 0 let g:autoformat_retab = 1 let g:autoformat_remove_trailing_spaces = 1 let g:formatdef_hl_js='"js-beautify"' let g:formatdef_hl_c='"clang-format -style=\"{BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, PointerAlignment: Right, ColumnLimit: 150, SpacesBeforeTrailingComments: 1}\""' "指定格式化的方式, 使用配置參數(shù) let g:formatters_c = ['hl_c'] let g:formatters_cpp = ['hl_c'] let g:formatters_json = ['hl_js'] let g:formatters_js = ['hl_js'] let g:formatdef_sqlformat = '"sqlformat --keywords upper -"' let g:formatters_sql = ['sqlformat'] "保存時(shí)自動(dòng)格式化指定文件類(lèi)型代碼 "au BufWrite *:Autoformat "autocmd BufWrite *.sql,*.c,*.py,*.java,*.js:Autoformat "設(shè)置發(fā)生保存事件時(shí)執(zhí)行格式化
與 AutoFormat
插件類(lèi)似, 本插件也相當(dāng)于一個(gè)錯(cuò)誤統(tǒng)計(jì)處理平臺(tái), 通過(guò)為不同語(yǔ)言配置不同 linter 來(lái)達(dá)到錯(cuò)誤統(tǒng)計(jì)的效果
如果你安裝了 lightline 或者其他的類(lèi)似工具, 那么也可以集成到你的底部工具欄中
安裝1 Plug 'dense-analysis/ale'
配置1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 "********************* dense-analysis/ale ************************ let b:ale_fixers = ['prettier', 'eslint'] let g:ale_fixers = { \ '*': ['remove_trailing_lines','trim_whitespace' ], \ 'python': ['autopep8'] \} let g:ale_set_highlights = 0 "let g:ale_fix_on_save = 1 "auto Sava let g:ale_echo_msg_format = '[#%linter%#] %s [%severity%]' let g:ale_sign_column_always = 1 "始終開(kāi)啟標(biāo)志列 let g:ale_sign_error = '·' let g:ale_sign_warning = '·' let g:ale_echo_msg_error_str = '?' let g:ale_echo_msg_warning_str = '?' let g:ale_completion_delay = 500 let g:ale_echo_delay = 20 let g:ale_lint_delay = 500 let g:ale_linters_explicit = 1 let g:ale_lint_on_text_changed = 'normal' let g:ale_lint_on_insert_leave = 1 let g:airline#extensions#ale#enabled = 1 let g:ale_c_gcc_options = '-Wall -O2 -std=c99' let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14' let g:ale_c_cppcheck_options = '' let g:ale_cpp_cppcheck_options = '' let g:ale_linters = { \ 'c': ['clangd'], \ 'swift': ['swiftlint'], \ 'markdown': ['markdownlint'], \ 'sh': ['shellcheck'], \ 'json': ['jsonlint'], \ 'zsh': ['shellcheck'] \} let g:ale_list_window_size = 5 let g:ale_statusline_format = ['E·%d', 'W·%d', 'OK']
1 2 3 " 快速跳轉(zhuǎn)至錯(cuò)誤的快捷鍵 nnoremap <Leader>en <Plug>(ale_next) nnoremap <Leader>ep <Plug>(ale_previous)
netrw很多人使用 vim 編輯文件, 完成后退出 vim 進(jìn)行目錄切換, 殊不知 vim 其實(shí)自帶路徑管理功能的, 從 vim 7 以后我們可以使用 vim 自帶的 netrw
進(jìn)入路徑管理窗口
netrw
是 vim 自帶的插件, 不需要額外安裝, 其提供的功能非常強(qiáng)大, 相比與 NERDTREE
這些第三方插件來(lái)說(shuō)速度更快, 體量更輕, 設(shè)計(jì)更簡(jiǎn)潔
操作命令
:Ex
: 全屏進(jìn)入 netrw
, 全稱(chēng)是 :Explorer
:Sex>
: 水平分割進(jìn)入 netrw
:Vex>
: 垂直分割進(jìn)入 netrw
<F1>
: 在 netrw 界面彈出幫助信息
<CR>
: 打開(kāi)光標(biāo)下文件 / 夾
-
: 進(jìn)入上一級(jí)目錄
p
: 預(yù)覽文件 (光標(biāo)保持不動(dòng))
P
: 打開(kāi)文件, 會(huì)在上一個(gè)使用的窗口一側(cè)的第一個(gè)窗口打開(kāi)文件
<C-w>z
: 關(guān)閉預(yù)覽窗口
gn
: 使光標(biāo)下的目錄作為目錄樹(shù)最頂部, 在 tree style 下與 <CR>
是不同的
d
: 創(chuàng)建文件夾
D
: 移除文件 / 夾
cd
: change 工作目錄到當(dāng)前路徑
I
: 顯示 / 隱藏頂部 banner
o
: 以水平分割窗口方式打開(kāi)光標(biāo)下文件
v
: 以垂直分割窗口方式打開(kāi)光標(biāo)下文件
%
: 在當(dāng)前目錄下新建一個(gè)文件并編輯
r
: 翻轉(zhuǎn)排序方式
qb
: 列出所有的目錄以及歷史路徑
qf
: 顯示文件詳細(xì)信息
R
: 重命名文件 / 文件夾
s
: 在 name
, time
和 file size
之間切換排序
t
: 新 tab 中打開(kāi)文件
<c-h>
: 編輯隱藏列表
<c-l>
: 更新 netrw 列表內(nèi)容
a
: 隱藏 / 顯示由 g: netrw_list_hide
所控制的文件
C
: 設(shè)置編輯窗口
gb
: 跳轉(zhuǎn)到上次標(biāo)記的書(shū)簽
gd
: 強(qiáng)制作為目錄
gf
: 強(qiáng)制作為文件
gh
: 快速隱藏 .
開(kāi)頭的文件
i
: 在 thin
, long
, wide
, tree listings
狀態(tài)之間切換
mb
: 將當(dāng)前目錄存為書(shū)簽
mc
: Copy marked files to marked-file target directory
mm
: Move marked files to marked-file target directory
md
: 對(duì)標(biāo)記的文件做 diff
操作
me
: 將標(biāo)記的文件放入?yún)?shù)列表中并進(jìn)行編輯
mf
: 標(biāo)記一個(gè)文件
mF
: 取消標(biāo)記一個(gè)文件
mg
: 對(duì)標(biāo)記的文件使用 vimgrep
命令
mp
: 打印標(biāo)記的文件
mr
: 使用 shell-style
標(biāo)記文件
mt
: 使當(dāng)前目錄成為標(biāo)記文件目標(biāo)
mT
: 對(duì)標(biāo)記文件應(yīng)用 ctags
mu
: 對(duì)所有標(biāo)記文件取消標(biāo)記
mz
: 壓縮 / 反壓縮標(biāo)記文件
O
: Obtain a file specified by cursor
qF
: Mark files using a quickfix list
S
: 確認(rèn)在 name 排序狀態(tài)下的擴(kuò)展名優(yōu)先級(jí)
u
: 跳轉(zhuǎn)到上一次瀏覽的目錄
x
: 使用系統(tǒng)中與之關(guān)聯(lián)的程序打開(kāi)光標(biāo)下文件
X
: 執(zhí)行光標(biāo)下的文件
配置1 2 3 4 5 6 7 8 9 10 11 let g:netrw_hide = 1 "設(shè)置默認(rèn)隱藏 let g:netrw_liststyle = 3 " tree 模式顯示風(fēng)格 let g:netrw_banner = 0 " 顯示幫助信息 let g:netrw_browse_split = 0 "控制 <CR> 直接在當(dāng)前窗口打開(kāi)光標(biāo)下文件 let g:netrw_winsize = 30 " 占用寬度 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+' " 需要隱藏的文件 let g:netrw_localrmdir = 'trash' "默認(rèn)的刪除工具使用 trash let g:netrw_altv = 1 " 控制 v 分裂的窗口位于右邊 let g:netrw_preview = 1 " 默認(rèn)是水平分割, 此項(xiàng)設(shè)置使之垂直分割 let g:netrw_alto = 0 " 控制預(yù)覽窗口位于左側(cè)或右側(cè), 與 netrw_preview 共同作用 " let g:netrw_chgwin = 2 " 控制按下 <CR> 的新文件在位于屏幕右側(cè)的 2 號(hào)窗口打開(kāi), Lex 默認(rèn)會(huì)設(shè)為 2
netrw copy 文件的方式netw 復(fù)制文件的方式比較費(fèi)解, 其原理是先標(biāo)記好一個(gè)源文件, 然后標(biāo)記好一個(gè)要被拷貝到的路徑, 最后使用拷貝命令進(jìn)行拷貝, 具體如下:
mf
標(biāo)記源文件
將光標(biāo)移動(dòng)至 ./
上, 然后使用 mt
標(biāo)記此目標(biāo)路徑
mc
拷貝文件至此 (也可以 mv
移動(dòng)文件至此)
不管出于任何原因不想使用 netrw
, 我們都有很多第三方插件可以選擇, NerdTree
就是其中的佼佼者
安裝
先在.vimrc 文件中添加 Plug 名稱(chēng)及設(shè)定:
1 2 3 4 5 6 7 8 9 Plug 'preservim/nerdtree' Plug 'Xuyuanp/nerdtree-git-plugin' "目錄樹(shù) git 狀態(tài)顯示 "F1 開(kāi)啟和關(guān)閉 NerdTree map <F1>:NERDTreeToggle<CR> let NERDTreeChDirMode=1 let NERDTreeShowBookmarks=1 "顯示書(shū)簽 let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$'] "設(shè)置忽略文件類(lèi)型 let NERDTreeWinSize=25 "窗口大小
運(yùn)行 vim, 輸入命令 :PlugInstall
操作命令
文件操作
e
: 進(jìn)入文件夾內(nèi)部瀏覽, 會(huì)在右側(cè)開(kāi)啟小窗口進(jìn)入文件夾列表
o
: 在預(yù)覽窗口中打開(kāi)文件, 左側(cè) NerdTree 仍然被保留 (事實(shí)上除非打開(kāi)新 tab 或手動(dòng)退出, 否在會(huì)一直存在)
O
: 遞歸地打開(kāi)其內(nèi)所有文件夾
go
: 在預(yù)覽窗口中打開(kāi)文件, 光標(biāo)將仍然保留在小窗口中, 非常好用, 用于預(yù)覽多個(gè)文件特別有用.
i
: 以分割視圖打開(kāi)文件
gi
: 以分割視圖打開(kāi), 但是光標(biāo)仍然保留在小窗口
s
: 以分割視圖打開(kāi)文件
gs
: 以分割視圖打開(kāi)文件, 但是光標(biāo)仍然保留在小窗口
t
: 在新標(biāo)簽頁(yè)打開(kāi)選擇的文件, 全屏
T
: 在新標(biāo)簽頁(yè)靜默打開(kāi)選擇的文件, 全屏, 因?yàn)槭庆o默, 所以不會(huì)跳轉(zhuǎn)到新窗口
C
: 將當(dāng)前所選文件夾改為根目錄, 即進(jìn)入到所選擇的文件夾, 與 o 不同, o 是在當(dāng)前視圖下將文件夾展開(kāi), C 則是直接進(jìn)入到文件夾.
cd
: 將當(dāng)前文件夾改為 cwd(當(dāng)前工作目錄)
CD
: 將文件夾目錄跳轉(zhuǎn)到 CWD(當(dāng)前工作目錄) 中
m
: 對(duì)所選擇的文件或文件夾彈出編輯菜單. 包括修改文件名, 復(fù)制, 移動(dòng), 刪除等操作
B
: 隱藏 / 顯示書(shū)簽, 如果顯示書(shū)簽, 還會(huì)將光標(biāo)自動(dòng)跳轉(zhuǎn)至?xí)?/li>
I
: 顯示系統(tǒng)隱藏文件
關(guān)閉移動(dòng)系列
q
: 直接退出 NerdTree
D
: 刪除書(shū)簽
F
: 隱藏文件, 只保留文件夾在視圖中
? j
: 當(dāng)同一個(gè) NerdTree 有多個(gè)目錄級(jí)別時(shí), 只在同一級(jí)別下向下移動(dòng)
? k
: 當(dāng)同一個(gè) NerdTree 有多個(gè)目錄級(jí)別時(shí), 只在同一級(jí)別下向上移動(dòng)
J
: 移動(dòng)到同一級(jí)別的最下方
K
: 移動(dòng)到同一級(jí)別的最上方
其他
A
: 全屏進(jìn)入 NerdTree 窗口
r
: 刷新當(dāng)前文件夾的緩存, 使界面刷新
R
: 刷新整個(gè)文件夾樹(shù)的緩存, 使整個(gè)界面更新
?
: 快速顯示幫助, 非常有用, 忘記功能時(shí)使用!
每次 NERDTree
從左側(cè)顯示出來(lái)的時(shí)候其所在目錄即工作目錄, 可以通過(guò) cd
命令進(jìn)行設(shè)置, 或者在 .vimrc
中設(shè)置 set autochair
進(jìn)行自動(dòng)切換, 這個(gè)概念對(duì)于文件批量操作很重要, 因?yàn)槲募坎僮鲿r(shí)添加待操作文件是依靠當(dāng)前工作目錄來(lái)進(jìn)行篩選的.
unimpaired一個(gè)映射了大量實(shí)用命令的插件, 主要前綴鍵是 [
與 ]
,
安裝1 Plug 'tpope/vim-unimpaired'
使用
[b
:bprevious
]b
:bnext
[B
:bfirst
]B
:blast
[Space
: 當(dāng)前行上增加空行
]Space
: 當(dāng)前行下增加空行
[e
: 當(dāng)前行上移
]e
: 當(dāng)前行下移
[f
:previous file in current directory
]f
:next file in current directory
<p
: 復(fù)制到當(dāng)前行下, 減少縮進(jìn)
<P
: 復(fù)制到當(dāng)前行上, 減少縮進(jìn)
=P
: 復(fù)制到當(dāng)前上, 自動(dòng)縮進(jìn)
>p
: 復(fù)制到當(dāng)前行下, 增加縮進(jìn)
>P
: 復(fù)制到當(dāng)前行上, 增加縮進(jìn)
[p
: 復(fù)制到當(dāng)前行上
]p
: 復(fù)制到當(dāng)前行下
[q
:cprevious, quickfix previous
]q
:cnext
[Q
:cfirst
]Q
:clast
[a
:previous
]a
:next
[A
:first
]A
:last
[l
:lprevious
]l
:lnext
[L
:lfirst
]L
:llast
[<C-L>
:lpfile
]<C-L>
:lnfile
[<C-Q>
:cpfile
]<C-Q>
:cnfile
[<C-T>
:ptprevious
]<C-T>
:ptnext
[n
:previous scm conflict
]n
:next scm conflict
[t
:tprevious, tag previous
]t
:tnext
[T
:tfirst
]T
:tlast
vim 下的輸入法自動(dòng)切換工具, 在進(jìn)入命令模式時(shí)自動(dòng)切換至英文輸入法, 回到插入模式時(shí)返回到上一次選擇的輸入法 (在需要中英文切換的環(huán)境中非常有用)
安裝
下載基礎(chǔ)工具 xkbswitch-macosx (每個(gè)系統(tǒng)有不同的實(shí)現(xiàn)工具, 這里以 macOS 為例)
1 2 3 4 5 git clone https://github.com/myshov/xkbswitch-macosx # 把 git 下來(lái)的 xkbswitch 弄到 /usr/local/bin 下, 其實(shí)環(huán)境變量能搜到就行 cp xkbswitch-macosx/bin/xkbswitch /usr/local/bin git clone https://github.com/myshov/libxkbswitch-macosx cp libxkbswitch-macosx/bin/libxkbswitch.dylib /usr/local/lib/
在 vim 中安裝插件
在 vimrc
中加入下面的內(nèi)容:
1 2 3 4 5 Plug 'lyokha/vim-xkbswitch', {'as': 'xkbswitch'} let g:XkbSwitchEnabled = 1 let g:XkbSwitchIMappings = ['cn'] let g:XkbSwitchIMappingsTr = {'cn': {'<': '', '>': ''}}
最后 PlugInstall
即可.
先在.vimrc 文件中添加 Plug 名稱(chēng)及設(shè)定:
1 2 Plug 'lyokha/vim-xkbswitch', {'as': 'xkbswitch'} let g:XkbSwitchEnabled = 1
運(yùn)行 vim, 輸入命令:PlugInstall
使用方式在 normal
模式下手動(dòng)切換至英文輸入法模式, 然后進(jìn)入 insert
模式后手動(dòng)切換到中文輸入法模式, 此時(shí)插件已經(jīng)記憶了輸入法的狀態(tài)了, 在 ESC
回到 normal
模式后會(huì)自動(dòng)切換到英文輸入法模式, 再次進(jìn)入 insert
模式時(shí)會(huì)自動(dòng)切換到中文輸入法模式
自動(dòng)補(bǔ)全匹配符號(hào)
安裝1 Plug 'jiangmiao/auto-pairs'
配置1 let g:AutoPairsMapCR = 0
映射
<M-p>
: Toggle Autopairs (g:AutoPairsShortcutToggle)
<M-e>
: Fast Wrap (g:AutoPairsShortcutFastWrap)
<M-n>
: Jump to next closed pair (g:AutoPairsShortcutJump)
<M-b>
: BackInsert (g:AutoPairsShortcutBackInsert)
<M-(>
/ <M-)>
/ <M-[>
/ <M-]>
/ <M-{>
/ <M-}>
/ <M-">
/ <M-'>
: Move character under the cursor to the pair
一款對(duì)齊插件, 快速按照給定的分隔符號(hào)完成指定范圍內(nèi)的對(duì)齊操作
安裝1 Plug 'godlygeek/tabular'
操作
:Tabularize /,/
: 將整個(gè)緩沖區(qū)的所有行按照 ,
符號(hào)進(jìn)行對(duì)齊
:'<,'>Tabularize /,/
: 對(duì)高亮選中范圍內(nèi)的行進(jìn)行對(duì)齊
:Tabularize /,/l1c1r0
: 按照 ,
進(jìn)行對(duì)齊, 并且為每個(gè)分割的文本區(qū)域內(nèi)的文本指定對(duì)齊方式, l
, c
, r
分別為左中右對(duì)齊, 1
代表每個(gè)分隔區(qū)域?qū)R補(bǔ)全后添加一個(gè)空格
1 2 3 4 5 6 7 8 9 abc,def,ghi a,b a,b,c :Tabularize /,/r1c1l0 abc, def, ghi a, b a, b, c
對(duì)于分隔符所處的區(qū)域, l
/ r
/ c
的作用是相同的, 因?yàn)槠渲挥幸粋€(gè)寬度
如果分隔的區(qū)塊足夠多, 那么將會(huì)循環(huán)使用 r1c1l0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 :Tabularize /,/r1c1l0 Some short phrase, some other phrase A much longer phrase here, and another long phrase That command would be read as 1. Align the matching text, splitting fields on commas. 2. Print everything before the first comma right aligned, then 1 space, 3. then the comma center aligned, then 1 space, 4. then everything after the comma left aligned." Notice that the alignment of the field the comma is in is irrelevant - since it's only 1 cell wide, it looks the same whether it's right, left, or center aligned. Also notice that the 0 padding spaces specified for the 3rd field are unused - but they would be used if there were enough fields to require looping through the fields again. For instance: abc,def,ghi a,b a,b,c :Tabularize /,/r1c1l0 abc, def, ghi a, b a, b, c
安裝
配置1 2 3 let g:user_emmet_mode='a' "enable all function in all mode. let g:user_emmet_leader_key='<C-y>' let g:user_emmet_install_global = 0
操作
div>ul>li
+ <C-y>,
: >
生成子節(jié)點(diǎn)
1 2 3 4 5 <div> <ul> <li></li> </ul> </div>
div+p+bq
+ <C-y>,
: +
生成兄弟節(jié)點(diǎn)
1 2 3 <div></div> <p></p> <blockquote></blockquote>
div+div>p>span+em^bq
+ <C-y>,
: ^
與 >
相反, 在父節(jié)點(diǎn)生成新節(jié)點(diǎn)
1 2 3 4 5 <div></div> <div> <p><span></span><em></em></p> <blockquote></blockquote> </div>
div+div>p>span+em^^^bq
+ <C-y>,
: 使用 n 個(gè) ^
, 就可以在第 n 父級(jí)生成新的節(jié)點(diǎn)
1 2 3 4 5 <div></div> <div> <p><span></span><em></em></p> </div> <blockquote></blockquote>
ul>li*5
+ <C-y>,
: 使用 *
生成多個(gè)相同元素
1 2 3 4 5 6 7 <ul> <li></li> <li></li> <li></li> <li></li> <li></li> </ul>
div>(header>ul>li*2>a)+footer>p
+ <C-y>,
: 圓括號(hào) ()
是 Emmet 的高級(jí)用法, 用來(lái)實(shí)現(xiàn)比較復(fù)雜的 DOM 結(jié)構(gòu)
1 2 3 4 5 6 7 8 9 10 11 <div> <header> <ul> <li><a href=""></a></li> <li><a href=""></a></li> </ul> </header> <footer> <p></p> </footer> </div>
(div>dl>(dt+dd)*3)+footer>p
+ <C-y>,
: 還可以嵌套使用圓括號(hào) ()
1 2 3 4 5 6 7 8 9 10 11 12 13 <div> <dl> <dt></dt> <dd></dd> <dt></dt> <dd></dd> <dt></dt> <dd></dd> </dl> </div> <footer> <p></p> </footer>
div#header+div.page+div#footer.class1.class2.class3
+ <C-y>,
: Emmet 給元素添加 ID 和 CLASS 的方法和 CSS 的語(yǔ)法類(lèi)似
1 2 3 <div id="header"></div> <div class="page"></div> <div id="footer" class="class1 class2 class3"></div>
td[title="Hello world!" colspan=3]
+ <C-y>,
: 使用 [attr]
標(biāo)記來(lái)添加自定義屬性
1 <td title="Hello world!" colspan="3"></td>
ul>li.item$*5
+ <C-y>,
: 使用 $
操作符可以對(duì)重復(fù)元素進(jìn)行有序編號(hào)
1 2 3 4 5 6 7 <ul> <li class="item1"></li> <li class="item2"></li> <li class="item3"></li> <li class="item4"></li> <li class="item5"></li> </ul>
ul>li.item$$$*5
+ <C-y>,
: 還可以用多個(gè) $
定義編號(hào)的格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <ul> <li class="item001"></li> <li class="item002"></li> <li class="item003"></li> <li class="item004"></li> <li class="item005"></li> </ul> <ul> <li class="item001"></li> <li class="item002"></li> <li class="item003"></li> <li class="item004"></li> <li class="item005"></li> </ul>
ul>li.item$@-*5
+ <C-y>,
: 使用 @
修飾符可以改變編號(hào)的格式, 在 $
后面添加 @-
可以改變編號(hào)順序
1 2 3 4 5 6 7 <ul> <li class="item4"></li> <li class="item3"></li> <li class="item2"></li> <li class="item1"></li> <li class="item0"></li> </ul>
ul>li.item$@3*5
+ <C-y>,
: 在 $
后面添加 @N
可以改變編號(hào)基數(shù)
1 2 3 4 5 6 7 <ul> <li class="item3"></li> <li class="item4"></li> <li class="item5"></li> <li class="item6"></li> <li class="item7"></li> </ul>
ul>li.item$@-3*5
+ <C-y>,
: 還可以組合使用上面的修飾符
1 2 3 4 5 6 7 <ul> <li class="item7"></li> <li class="item6"></li> <li class="item5"></li> <li class="item4"></li> <li class="item3"></li> </ul>
a{click}+b{here}
+ <C-y>,
: Emmet 使用 Text:{}
給元素添加文本內(nèi)容
1 2 <a href="">click</a> <b>here</b>
a>{click}+b{here}
+ <C-y>,
:
1 <a href="">click<b>here</b></a>
p>{Click }+a{here}+{ to continue}
+ <C-y>,
:
1 2 3 4 5 <p> Click <a href="">here</a> to continue </p>
#page>div.logo+ul#navigation>li*5>a{Item $}
+ <C-y>,
:
1 2 3 4 5 6 7 8 9 10 <div id="page"> <div class="logo"></div> <ul id="navigation"> <li><a href="">Item 1</a></li> <li><a href="">Item 2</a></li> <li><a href="">Item 3</a></li> <li><a href="">Item 4</a></li> <li><a href="">Item 5</a></li> </ul> </div>
快捷鍵
<Ctrl-y>,
: 展開(kāi)簡(jiǎn)寫(xiě)式
<Ctrl-y>d
: Balance a Tag Inward(選中包圍的標(biāo)簽?)
<Ctrl-y>D
: Balance a Tag Outward
<Ctrl-y>n
: 進(jìn)入下個(gè)編輯點(diǎn)
<Ctrl-y>N
: 進(jìn)入上個(gè)編輯點(diǎn)
<Ctrl-y>i
: 更新 <img>
圖像尺寸
<Ctrl-y>m
: 合并文本行
<Ctrl-y>k
: 刪除標(biāo)簽
<Ctrl-y>j
: 分解 / 展開(kāi)空標(biāo)簽
<Ctrl-y>/
: 注釋開(kāi)關(guān)
<Ctrl-y>a
: 從 URL 生成 anchor 標(biāo)簽
<Ctrl-y>A
: 從 URL 生成引用文本
一款在瀏覽器中預(yù)覽 markdown 文件的插件
安裝1 Plug 'iamcco/markdown-preview.nvim', {'do': 'cd app & yarn install'}
運(yùn)行 vim, 輸入命令:PlugInstall
配置1 2 3 4 5 6 7 8 map <F3>:MarkdownPreview<CR> "設(shè)置 F3 開(kāi)啟 Markdown 文件預(yù)覽 let g:mkdp_auto_start = 0 "打開(kāi)文件后自動(dòng)彈出, 0 為否 let g:mkdp_auto_close = 1 "關(guān)閉文件后自動(dòng)關(guān)閉預(yù)覽窗口, 1 為是 let g:mkdp_refresh_slow = 1 "慢速預(yù)覽, 修改后退出 insert 模式后方會(huì)刷新視圖, 1 為是 let g:mkdp_open_to_the_world = 0 "開(kāi)啟公網(wǎng)鏈接, 0 為否 let g:mkdp_browser = '' "指定瀏覽器, 默認(rèn)會(huì)跟隨系統(tǒng)瀏覽器 let g:mkdp_port = '' " 指定端口, 默認(rèn)隨機(jī)端口 let g:mkdp_page_title = ' **${name}** ' "指定瀏覽器窗口標(biāo)題, 默認(rèn)為 Markdown 文件名
操作命令
:MarkdownPreview
: 開(kāi)啟預(yù)覽
:MarkdownPreviewStop
: 停止預(yù)覽
:MarkdownPreviewTroggle
: 開(kāi)關(guān)預(yù)覽
在窗口右側(cè)顯示 markdown 目錄結(jié)構(gòu)的一個(gè)插件, 此插件基于 ctags 和 tagbar(Tagbar 是一個(gè)著名的文檔目錄顯示插件, 但是不支持 markdown, 此插件在 Tagbar 的基礎(chǔ)上添加了對(duì) markdown 的支持). 因此此插件必須同時(shí)安裝以上兩種插件方可正常工作
安裝
通過(guò) brew
安裝 ctgs
在 .vimrc
文件中添加 Plug
名稱(chēng)
1 2 Plug 'jszakmeister/markdown2ctags' Plug 'majutsushi/tagbar'
配置1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 "***************** Tagbar ************************************* "F4 開(kāi)啟和關(guān)閉 map <F4>:TagbarToggle<CR> let g:tagbar_type_markdown = { \ 'ctagstype': 'markdown', \ 'ctagsbin': '~/.vim/plugged/markdown2ctags/markdown2ctags.py', \ 'ctagsargs': '-f - --sort=yes ', \ 'kinds': [ \ 's:sections', \ 'i:images' \ ], \ 'sro': '|', \ 'kind2scope': { \ 's': 'section', \ }, \ 'sort': 0, \ }
使用只要在 vim 界面中使用 :TagbarToggle
即可調(diào)出 Tagbar 界面, 即可顯示 markdown 的目錄結(jié)構(gòu).
一款 markdown 語(yǔ)法檢查工具, 可以根據(jù)預(yù)設(shè)的規(guī)則進(jìn)行 markdown 語(yǔ)法錯(cuò)誤警告或提示, 可根據(jù)需要進(jìn)行規(guī)則自定義
安裝1 brew install markdownlint-cli
使用配合 ALE 插件一起使用
1 2 3 4 5 6 7 let g:ale_linters = { \ 'c': ['clangd'], \ 'swift': ['swiftlint'], \ 'markdown': ['markdownlint'], \ 'sh': ['shellcheck'], \ 'zsh': ['shellcheck'] \}
配置規(guī)則在項(xiàng)目根目錄下建立 .markdownlint.json
配置文件, 在其中對(duì)默認(rèn)的規(guī)則進(jìn)行配置, ale markdownlint 工具在被調(diào)用的時(shí)候會(huì)自動(dòng)去查找該名稱(chēng)配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "default": true, "MD013": false, "MD014": false, "MD024": false, "MD029": false, "MD033": false, "MD040": false, "no-hard-tabs": false, "no-inline-html": { "allowed_elements": [ "a" ] } }
fuzzy find
, 快速模糊搜索查找工具
fzf.vim 與 終端工具 fzf 配合使用, 在 vim 中的 :FZF
與 Files
命令都會(huì)調(diào)用 export FZF_DEFAULT_COMMAND='...'
這個(gè)參數(shù), 需要在 .zshrc
中配置好
安裝
在終端中安裝 fzf 工具
~/.vimrc
中安裝 vim 的 fzf
插件
1 2 Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim'
配置使用首先在 .zshrc
中配置終端中的 fzf 選項(xiàng), 如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 export FZF_DEFAULT_COMMAND="fd --hidden --follow -I --exclude={Pods,.git,.idea,.sass-cache,node_modules,build} --type f" export FZF_DEFAULT_OPTS=" --color=dark --color=fg:#707a8c,bg:-1,hl:#3e9831,fg+:#cbccc6,bg+:#434c5e,hl+:#5fff87 --color=info:#af87ff,prompt:#5fff87,pointer:#ff87d7,marker:#ff87d7,spinner:#ff87d7 --height 60% --layout reverse --preview-window 'hidden:right:60%' --preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -N -C {}) 2> /dev/null | head -500' --bind ',:toggle-preview' --border --cycle " export FZF_CTRL_T_COMMAND=$FZF_DEFAULT_COMMAND export FZF_CTRL_T_OPTS=$FZF_DEFAULT_OPTS export FZF_CTRL_R_OPTS=" --layout=reverse --sort --exact --preview 'echo {}' --preview-window down:3:hidden:wrap --bind ',:toggle-preview' --cycle " export FZF_ALT_C_OPTS="--preview 'tree -N -C {} | head -500'" export FZF_TMUX_OPTS="-d 60%" export FZF_COMPLETION_TRIGGER='**'
(fzf 可擴(kuò)展性很高, 如果進(jìn)行適當(dāng)配置, 它可以在你進(jìn)行路徑跳轉(zhuǎn), 歷史命令搜索, 文件搜索等方面給你極大的幫助!)
然后在 vim 中配置 fzf 插件的相關(guān)設(shè)置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 nnoremap <Leader>fh:History<CR> nnoremap <Leader>fl:Lines<CR> nnoremap <Leader>fb:Buffers<CR> nnoremap <Leader>ff:Files<CR> nnoremap <Leader>fg:GFiles<CR> nnoremap <Leader>f?:GFiles?<CR> nnoremap <Leader>ft:Tags<CR> nnoremap <Leader>fa:Ag<CR> nnoremap <Leader>fc:Commits<CR> let g:fzf_preview_window = 'right:60%' " Always enable preview window on the right with 60% width let g:fzf_buffers_jump = 1 " [Buffers] Jump to the existing window if possible " [[B]Commits] Customize the options used by 'git log' let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' let g:fzf_tags_command = 'ctags -R' " [Tags] Command to generate tags file let g:fzf_commands_expect = 'alt-enter,ctrl-x' " [Commands] --expect expression for directly executing the command let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', \ 'ctrl-v': 'vsplit' \} let g:fzf_layout = { 'down': '~60%' }
命令:Files [path]
: 列出 path 路徑下的所有文件 (功能等價(jià)于 :FZF
命令)
:Buffers
: 文件緩沖區(qū)切換
:Colors
: 選擇 Vim 配色方案
:Tags [QUERY]
: 當(dāng)前項(xiàng)目中的 Tag (等價(jià)于: ctags -R)
:BTags
: [QUERY] 當(dāng)前活動(dòng)緩沖區(qū)的標(biāo)記
:Marks
: 所有 Vim 標(biāo)記
:Windows
: 窗口
:Lines [QUERY]
: 在所有加載的文件緩沖區(qū)里包含目標(biāo)詞的所有行
:BLines [QUERY]
: 在當(dāng)前文件緩沖區(qū)里包含目標(biāo)詞的行
:Locate PATTERN
: locate command output
:History
: v:oldfiles and open buffers
:History:
: 命令行命令歷史
:History/
: 搜索歷史
:Commands
: Vim 命令列表
:Maps
: 普通模式下的按鍵映射
:Snippets
: Snippets ([UltiSnips][us])
:Commits
: Git commits (requires [fugitive.vim][f])
:BCommits
: 查看與當(dāng)前緩沖區(qū)有關(guān)的 commit
:GFiles [OPTS]
: Git files (git ls-files)
:GFiles?
: Git files (git status)
:Ag [PATTERN]
: ag search result (ALT-A to select all, ALT-D to deselect all)
:Rg [PATTERN]
: rg search result (ALT-A to select all, ALT-D to deselect all)
:Filetypes
: File types
補(bǔ)全插件, 支持 c
, c++
, java
, python
, PHP
等多語(yǔ)言
安裝
先在 .vimrc
文件中添加 Plug 名稱(chēng)
1 Plug 'ycm-core/YouCompleteMe'`
運(yùn)行 vim, 輸入命令 :PlugInstall
經(jīng)歷過(guò)上述 2 個(gè)步驟后, YouCompleteMe 插件還沒(méi)法使用, 此時(shí)打開(kāi) Vim 時(shí)會(huì)看到如下的報(bào)錯(cuò):
1 2 The ycmd server SHUT DOWN (restart with ':YcmRestartServer’). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.
這是因?yàn)? YouCompleteMe 需要手工編譯出庫(kù)文件 ycm_core.so (以及依賴(lài)的 libclang.so) 才可使用. 假設(shè)使用 vim-plug 下載的 YouCompleteMe 源碼保存在目錄 ~/.vim/plugged/YouCompleteMe, 在該目錄下執(zhí)行
1 2 3 4 5 # 編譯全部語(yǔ)言 ./install.py --all # 或者 /usr/bin/python install.py # 或僅編譯 C 族語(yǔ)言 ./install.py --clang-completer
基于 lsp 的補(bǔ)全插件, 基本上支持 lsp 的語(yǔ)言都可以使用此插件進(jìn)行補(bǔ)全. 此插件利用了 vsc 的插件生態(tài), 方案比較成熟, 推薦使用 (作者是國(guó)人)
命令
CocInstall <plugin>
: 安裝插件
CocUninstall
: 卸載插件
CocConfig
: 打開(kāi)配置文件 (vim: ~/.vim/coc-settings.json
)
CocLocalConfig
: 打開(kāi)本地配置文件
CocEnable
: 開(kāi)啟 coc
CocDisable
: 關(guān)閉
CocUpdate
: 升級(jí)插件
CocList <flag>
: 列出相關(guān)內(nèi)容
diagnostic
: 診斷信息
extension
: 所有插件
commands
: 所有可用命令
outline
: 大綱
symbols
: symbols
常用插件1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 coc-clangd coc-cmake coc-css coc-diagnostic coc-dictionary coc-emoji coc-flutter coc-gitignore coc-go coc-highlight coc-html coc-java coc-json coc-julia coc-markdownlint coc-omni coc-pyright coc-r-lsp coc-rome coc-rust-analyzer coc-sh coc-snippets coc-solargraph coc-sourcekit coc-syntax coc-tabnine coc-tag coc-tsserver coc-vetur coc-vimlsp coc-word coc-yaml coc-yank
管理 tag 文件, tag 文件關(guān)乎著項(xiàng)目的引用與跳轉(zhuǎn), 因此是一個(gè)比較大的話(huà)題, 詳細(xì)可以參考 韋大的文章
安裝
安裝 universal-ctags
命令行程序
1 2 brew tap universal-ctags/universal-ctags brew install --HEAD universal-ctags
安裝 vim 插件 vim-gutentags
1 Plug 'ludovicchabant/vim-gutentags'
配置1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 "***************** gutentags ************************************* let g:gutentags_project_root = ['.root', '.svn', '.git', '.hg', '.project'] " gutentags 搜索工程目錄的標(biāo)志, 當(dāng)前文件路徑向上遞歸直到碰到這些文件 / 目錄名 let g:gutentags_ctags_tagfile = '.tags' " 所生成的數(shù)據(jù)文件的名稱(chēng) let g:gutentags_modules = [] " 同時(shí)開(kāi)啟 ctags 和 gtags 支持: if executable('ctags') let g:gutentags_modules += ['ctags'] endif if executable('gtags-cscope') && executable('gtags') let g:gutentags_modules += ['gtags_cscope'] endif let g:gutentags_cache_dir = expand('~/.cache/tags') " 將自動(dòng)生成的 ctags/gtags 文件全部放入 ~/.cache/tags 目錄中 " 配置 ctags 的參數(shù), 老的 Exuberant-ctags 不能有 --extra=+q, 注意 let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q'] let g:gutentags_ctags_extra_args += ['--c++-kinds=+px'] let g:gutentags_ctags_extra_args += ['--c-kinds=+px'] let g:gutentags_ctags_extra_args += ['--output-format=e-ctags'] " 如果使用 universal ctags 需要增加下面一行, 老的 Exuberant-ctags 不能加下一行 let g:gutentags_auto_add_gtags_cscope = 0 " 禁用 gutentags 自動(dòng)加載 gtags 數(shù)據(jù)庫(kù)的行為
為系統(tǒng)頭文件生成 tags默認(rèn)情況下, 我們不能跳轉(zhuǎn)到 printf
這類(lèi)標(biāo)準(zhǔn)庫(kù)中的方法中, 如果需要的話(huà), 我們可以為系統(tǒng)標(biāo)準(zhǔn)庫(kù)生成 tags, 然后將在 .vimrc
文件中為其進(jìn)行指定, 這樣即可跳轉(zhuǎn)到系統(tǒng)的標(biāo)準(zhǔn)庫(kù)頭文件定義中了.
首先將系統(tǒng)中的頭文件目錄找出來(lái), 然后使用 ctags 對(duì)目錄中所有文件進(jìn)行生成
1 ctags --fields=+niazS --extras=+q --c++-kinds=+px --c-kinds=+px --output-format=e-ctags -R -f ~/.vim/systags /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include ~/header
然后在 vim
中指定 tags 文件的路徑即可
1 set tags+=~/.vim/systags
vim 下最好的 git 插件, 同時(shí)也是 git 下最好的 vim 插件
fugitive objectfugitive 插件操作的對(duì)象名為 fugitive object
, 可以是文件也可以是 commit, 下面列舉了一些 fugitive object
的表示方式
@
: The commit referenced by @ aka HEAD
master
: The commit referenced by master
master^
: The parent of the commit referenced by master
master...other
: The merge base of master and other
master:
: The tree referenced by master
./master
: The file named master in the working directory
:(top)master
: The file named master in the work tree
Makefile
: The file named Makefile in the work tree
@^:Makefile
: The file named Makefile in the parent of HEAD
:Makefile
: The file named Makefile in the index (writable)
@~2:%
: The current file in the grandparent of HEAD
:%
: The current file in the index
:1:%
: The current file's common ancestor during a conflict
:2:#
: The alternate file in the target branch during a conflict
:3:#5
: The file from buffer #5 in the merged branch during a conflict
!
: The commit owning the current file
!:Makefile
: The file named Makefile in the commit owning the current file
!3^2
: The second parent of the commit owning buffer #3
.git/config
: The repo config file
:
: The |fugitive-summary| buffer
-
: A temp file containing the last |:Git| invocation's output
<cfile>
: The file or commit under the cursor
commnads
:Git
: 進(jìn)入 summary 界面
:Git <arbitrary subcommand>
: 所有 command line 中 git...
后面可以使用的 subcommand 都可以使用, 比如 :Git push
, :Git push
, 甚至是在 ~/.gitconfig
中的 git alias
.
:Git <arbitrary subcommand> -p
: 與上命令相同, 不過(guò)會(huì)將命令結(jié)果單獨(dú)開(kāi)一個(gè)頁(yè)面進(jìn)行顯示
:Git blame
: 對(duì)當(dāng)前文件執(zhí)行 git blame
命令
:Gclog[!]
: 將本 repo 的所有 log 輸出至 quickfix, 并跳轉(zhuǎn)至第一個(gè) commit 的信息頁(yè)面 (添加 !
可以防止跳轉(zhuǎn))
:Gllog[!]
: 與 Gclog
相同, 但是將結(jié)果輸出至 location list
:[range]Gclog[!]
: 給定范圍 (比如選中多行), 然后使用 Gclog
的話(huà)會(huì)將與范圍相關(guān)的所有 commit 列出, 可以使用 :0Gclog!
來(lái)將與本文件相關(guān)的所有 commit 列出
:Gread [object]
: 如果不傳 fugitive object
, 則等同于 git checkout -- file
, 如果傳了, 則先將本 buffer 清空, 然后讀取指定的 fugitive-object
內(nèi)容到本 buffer 中
:Gwrite
: 類(lèi)似于 git add
:Gcd [directory]
: cd 到本 root 的根目錄下
:Gedit [object]
: edit 一個(gè) fugitive object
:Gdiffsplit [object]
: 使用 vimdiff
查看給定的 object
與當(dāng)前 file
的差異, 如果給定的是一個(gè) commit
, 那么會(huì)將該 commit 中的本文件與當(dāng)前本文件進(jìn)行差異對(duì)比
:Gvdiffsplit [object]
: 與 :Gdiffsplit
相同, 但是永遠(yuǎn) split vertically.
:Ghdiffsplit [object]
: 與 :Gdiffsplit
相同, 但是永遠(yuǎn) split horizontally.
:GMove {destination}
Wrapper around git-mv that renames the buffer afterward. Add a! to pass -f.
:GRename {destination}
Like |:GMove| but operates relative to the parent directory of the current file.
:GDelete
: 與 git rm --cached **
相同, Add a! to pass -f and forcefully discard the buffer.
:GRemove
: 與 GDelete
相同, 但是保持空 buffer 存在
:GBrowse
: 在 GitHub 中查看當(dāng)前 file / commit
鍵位映射
blame
A
: resize to end of author column
C
: resize to end of commit column
D
: resize to end of date/time column
gq
: close blame, then :Gedit
to return to work tree version
<CR>
: close blame, and jump to patch that added line (or directly to blob for boundary commit)
o
: jump to patch or blob in horizontal split
O
: jump to patch or blob in new tab
p
: jump to patch or blob in preview window
-
: reblame at commit
~
: reblame at [count]th first grandparent
P
: reblame at [count]th parent (like HEAD^[count])
stage/unstaging
s
: Stage (add) the file or hunk under the cursor.
u
: Unstage (reset) the file or hunk under the cursor.
-
: Stage or unstage the file or hunk under the cursor.
U
: Unstage everything.
X
: Discard the change under the cursor.
=
: Toggle an inline diff of the file under the cursor.
>
: Insert an inline diff of the file under the cursor.
<
: Remove the inline diff of the file under the cursor.
gI
: Open.git/info/exclude in a split and add the file under the cursor. Use a count to open.gitignore.
I
: Invoke |:Git| add --patch or reset --patch on the file
P
: under the cursor. On untracked files, this instead
gq
: Close the status buffer.
diff
dd
: Perform a |:Gdiffsplit| on the file under the cursor.
dv
: Perform a |:Gvdiffsplit| on the file under the cursor.
ds
: Perform a |:Ghdiffsplit| on the file under the cursor.
navigation
<CR>
: Open the file or |fugitive-object| under the cursor. In a blob, this and similar maps jump to the patch from the diff where this was
added, or where it was removed if a count was given. If the line is still in the work tree version, passing a count takes you to it.
o
: Open the file or fugitive-object
under the cursor in a new split.
gO
: Open the file or fugitive-object
under the cursor in a new vertical split.
O
: Open the file or fugitive-object
under the cursor in a new tab.
p
: Open the file or fugitive-object
under the cursor in a preview window. In the status buffer, 1p is required to bypass the legacy usage instructions.
~
: Open the current file in the [count]th first ancestor.
P
: Open the current file in the [count]th parent.
C
: Open the commit containing the current file.
常用流程
:Gdiffsplit HEAD
查看當(dāng)前 file 的所有相關(guān) commit
:0Gclog!
一款基于 fugitive
的查看 vim commit 樹(shù)形圖的工具
command
:GV
: to open commit browser
:GV!
: will only list commits that affected the current file
:GV?
: fills the location list with the revisions of the current file
map
o
/ <cr>
on a commit to display the content of it
o
/ <cr>
on commits to display the diff in the range
O
: opens a new tab instead
gb
: for:Gbrowse
]]
: and [[ to move between commits
.
: to start command-line with:Git [CURSOR] SHA à la fugitive
q
: or gq to close
一款超級(jí)強(qiáng)大的快速添加 / 刪除 / 改變包圍符號(hào)的神器
安裝1 Plug 'tpope/vim-surround'
命令
ds
: 刪除包圍符號(hào)
cs
: 改變包圍符號(hào)
ysw
: 當(dāng)前至下一個(gè)詞尾添加一個(gè)包圍符號(hào)
ysW
: 當(dāng)前至至下一個(gè)空格添加一個(gè)包圍符號(hào)
ySw
: 當(dāng)前至下一個(gè)詞尾添加一個(gè)包圍符號(hào)并將焦點(diǎn)移至下一行
ySW
: 當(dāng)前至下一個(gè)空格添加一個(gè)包圍符號(hào)并將焦點(diǎn)移至下一行
yss)
: 整行添加包圍符號(hào) ()
ysiw)
: 為當(dāng)前光標(biāo)下單詞添加包圍符號(hào) ()
S"
: Visual 模式下對(duì)選中區(qū)域添加包圍符號(hào) "
gS"
: Visual 模式下對(duì)選中區(qū)域進(jìn)行換行并添加包圍符號(hào)
?-s
: Insert 模式下插入包圍符號(hào)
?-s, ?-s
: Insert 模式下在插入包圍符號(hào)并將焦點(diǎn)移至下一行
dst
: 刪除 html/xml 的標(biāo)簽內(nèi)部的所有字符
cst
: 刪除 html/xml 的標(biāo)簽內(nèi)部的所有字符并進(jìn)入插入模式
ysa<'
: 在 <>
包裹的范圍上加符號(hào) '
范例1 2 3 4 5 6 7 8 9 | Old text | Command | New text | | :-------------------: | :-----: | :-----------------------: | | "Hello *world!" | ds" | Hello world! | | [123+4*56]/2 | cs]) | (123+456)/2 | | "Look ma, I'm *HTML!" | `cs"<a>` | `<a>Look ma, I'm HTML!</a>` | | 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>` |
快速注釋插件
安裝1 Plug 'preservim/nerdcommenter'
命令
<leader>cc
: NERDCommenterComment, 注釋當(dāng)前行或所選擇行 (文本)
<leader>cu
: NERDCommenterUncomment, 取消當(dāng)前所處位置的注釋狀態(tài) Uncomments the selected line(s).
<leader>ci
: NERDCommenterInvert, 反轉(zhuǎn)所選擇行的注釋狀態(tài) (逐個(gè)地反轉(zhuǎn)) 僅支持行
<leader>c<space>
: NERDCommenterToggle (反) 激活所選擇行的注釋狀態(tài), 依據(jù)最頂部行的注釋狀態(tài)進(jìn)行判斷, 執(zhí)行命令后, 所選擇行的注釋狀態(tài)均為最頂部行注釋狀態(tài)的相反狀態(tài). 僅支持行
<leader>cn
: NERDCommenterNested, 與 cc 相同, 不過(guò)嵌套地進(jìn)行注釋
<leader>cs
: NERDCommenterSexy, 將當(dāng)前選擇文本以塊的方式進(jìn)行注釋 (即在選擇文本的上方與下方加上單行注釋) 僅支持行
<leader>cy
: NERDCommenterYank, 與 cc 完全相同, 不過(guò)會(huì)先進(jìn)行復(fù)制操作
<leader>c$
: NERDCommenterToEOL Comments the current line from the cursor to the end of line.
<leader>cA
: NERDCommenterAppend, Adds comment delimiters to the end of line and goes into insert mode between them.
<leader>ca
: NERDCommenterAltDelims Switches to the alternative set of delimiters.
<leader>cm
: NERDCommenterMinimal, Comments the given lines using only one set of multipart delimiters.
快速注釋插件, 相比于 nerdcommenter
更加簡(jiǎn)潔實(shí)用
安裝1 Plug 'tpope/vim-commentary'
命令
gcc
: 注釋或反注釋
gcap
: 注釋一段
gc
: visual 模式下直接注釋所有已選擇的行
實(shí)現(xiàn)真正的多光標(biāo)的一個(gè)插件, vim 的 visual block 模式并不是多光標(biāo), 如果想將 visual block 模式下被選中的多行的當(dāng)前單詞推進(jìn)到每個(gè)單詞的末尾, 那么就需要使用到多光標(biāo)的概念.
我理解的此多光標(biāo)插件的使用分為兩種狀態(tài)
從 normal 模式直接使用 <C-n>
進(jìn)入多光標(biāo)狀態(tài)并選中當(dāng)前光標(biāo)下的單詞, 然后再次使用 <C-n>
選擇下一個(gè), <C-x>
跳過(guò)當(dāng)前符合的單詞, 最后進(jìn)行插入修改等操作
從 visual 或 visual block 模式下使用 <C-n>
進(jìn)入直接添加光標(biāo)到當(dāng)前所有行的選中單詞處, 然后移動(dòng)光標(biāo), 在合適位置進(jìn)行進(jìn)行插入修改等操作, 最后 esc 兩次退出
安裝1 Plug 'terryma/vim-multiple-cursors'
命令
<C-n>
: 進(jìn)入多光標(biāo)狀態(tài) / 或選擇下一個(gè)符合當(dāng)前選擇的單詞
<C-x>
: 跳過(guò)當(dāng)前候選
<C-p>
: 移除當(dāng)前單詞處的光標(biāo)及選擇狀態(tài)跳轉(zhuǎn)到上一個(gè)光標(biāo)處
1 2 3 4 5 6 7 8 9 10 11 let g:multi_cursor_use_default_mapping=0 " Default mapping let g:multi_cursor_start_word_key = '<C-n>' let g:multi_cursor_select_all_word_key = '<A-n>' let g:multi_cursor_start_key = 'g<C-n>' let g:multi_cursor_select_all_key = 'g<A-n>' let g:multi_cursor_next_key = '<C-n>' let g:multi_cursor_prev_key = '<C-p>' let g:multi_cursor_skip_key = '<C-x>' let g:multi_cursor_quit_key = '<Esc>'
安裝1 Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Maps
<C-n>
: 選擇當(dāng)前光標(biāo)所在的單詞, 進(jìn)入 V-M
(visual multi) 模式
<C-Down>
/ <C-Up>
: 創(chuàng)建垂直光標(biāo)選區(qū)
<S-Arrows>
: 一次創(chuàng)建一個(gè)字符選區(qū)
n
/ N
: 選擇下一個(gè)出現(xiàn)的相同字符
[/
/ ]
: 跳轉(zhuǎn)到上一個(gè) / 下一個(gè)選區(qū)處
q
: 跳過(guò)當(dāng)前并選擇下一個(gè)出現(xiàn)的地方
Q
: 移除當(dāng)前的選取
i
/ a
/ I
/ A
: 進(jìn)入插入模式
<Tab>
: 在 cursor mode
與 extend mode
之間切換
在 V-M
模式中, 絕大多數(shù) vim 命令都是可以使用的, 比如 r
, ~
一個(gè)異步批量搜索替換工具
安裝
Commands
CtrlSF [pattern]
: 搜索匹配字符串
Maps
在 CtrlSF window
中:
<CR>
/ o
: 在相應(yīng)的文件中打開(kāi)相應(yīng)的行
<C-O>
: 在 horizontal split window
中打開(kāi)
t
: 在新 tab 中打開(kāi)
p
: 在 preview 中打開(kāi)
P
: 在 preview 中打開(kāi)并將焦點(diǎn)移動(dòng)到 preview 上
O
: 與 o
相同, 但是保持 CtrlSF
開(kāi)啟
T
: 與 t
相同, 但是保持 focus 在 CtrlSF 上
M
: 在 normal view
(sublime) 與 compact view
(quick-fix) 切換
q
: 退出 CtrlSF
<C-j>
: 移動(dòng)光標(biāo)到下一個(gè)匹配處
<C-k>
: 移動(dòng)光標(biāo)到上一個(gè)匹配處
<C-c>
: 停止搜索
在 preview window
中
一套配色 vim 配色方案, 韓國(guó)人出品. 與之匹配的還有一個(gè) iTerm 配色方案, 兩者結(jié)合的比較好看
安裝在.vimrc 文件中添加 Plug 名稱(chēng)及設(shè)定:
1 2 3 4 5 6 7 Plug 'junegunn/seoul256.vim' colo seoul256 let g:seoul256_background = 236 "設(shè)置背景顏色深度 set background=dark "設(shè)置背景顏色為黑色, 必須設(shè)置, 否則上面的數(shù)值設(shè)置沒(méi)有意義 " seoul256 (dark): " Range: 233 (darkest) ~ 239 (lightest) " Default: 237
一款專(zhuān)注寫(xiě)作的 vim 插件, 開(kāi)啟后四周空白, 更利于專(zhuān)注. 不適用于寫(xiě)代碼和看代碼
安裝
在.vimrc 文件中添加 Plug 名稱(chēng)及設(shè)定:
1 Plug 'junegunn/goyo.vim'
命令
:Goyo
: 進(jìn)入專(zhuān)注模式
:Goyo!
: 退出專(zhuān)注模式, 或使用:q
:Goyo 90%
: 調(diào)整高度為窗口的 90%
:Goyo x30%
: 調(diào)整寬度為窗口的 30%
:Goyo 70%-10x90%+10%
: 調(diào)整區(qū)域?qū)挒榇翱?70%, 左邊距向左移 10 單位, 高度為窗口 90%, 向下移動(dòng)窗口的 10%
與 Goyo
, seoul256
為同一開(kāi)發(fā)者, 聯(lián)合使用效果最佳. 不適用于寫(xiě)代碼和看代碼.
官網(wǎng)
安裝在 .vimrc
文件中添加 Plug
名稱(chēng)及設(shè)定:
1 2 3 4 5 6 Plug 'junegunn/limelight.vim' let g:limelight_default_coefficient = 0.5 // 設(shè)置隱西藏域的黑暗度, 值越大越暗 let g:limelight_paragraph_span = 2 // 設(shè)置暗光的跨度, 暗光所能照亮的范圍 let g:limelight_priority = -1 // 暗光優(yōu)先級(jí), 防止搜索的高亮效果被覆蓋 autocmd! User GoyoEnter Limelight // 進(jìn)入 Goyo 專(zhuān)注插件時(shí), 同時(shí)開(kāi)啟暗光效果 autocmd! User GoyoLeave Limelight! // 離開(kāi) Goyo 專(zhuān)注插件時(shí), 同時(shí)退出暗光效果
命令
:Limelight
// 進(jìn)入 Limelight 狀態(tài)
:Limelight!
// 退出 Limelight 狀態(tài)
:Limelight0.3
//
如果你同時(shí)是一名 iOS 開(kāi)發(fā)者, 那么 XVim
可以幫助你在 Xcode
中找回缺失的 Vim
操作, XVim 可以讓 Xcode 像 vim 一樣編輯.
由于 XVim 沒(méi)有上架到 Mac App Store, 因此我們需要進(jìn)入官網(wǎng)下載源碼編譯按照, 編譯前需要對(duì) Xcode 進(jìn)行自簽名, 否則我們自己編譯出來(lái)的結(jié)果文件是不能安裝到 Xcode 上的
官網(wǎng)
安裝
對(duì)系統(tǒng)的代碼證書(shū)重新生成
XVimProject/XVim2
克隆源碼倉(cāng)庫(kù)
1 git clone https://github.com/XVimProject/XVim2.git
確認(rèn) xcode 內(nèi)容點(diǎn)
1 2 xcode-select -p /Applications/Xcode.app/Contents/Developer
如果有多個(gè)版本 Xcode, 此項(xiàng)會(huì)讓你清楚你將安裝 XVim 到哪一個(gè)版本上, 如果結(jié)果不是你想要的版本, 那么使用 xcode-select -s <path-of-xcode>
進(jìn)行手動(dòng)指定
make
按照需要可生成 .xvimrc
文件 ( .xvimrc
文件必須放在用戶(hù)主目錄, 即 .vimrc
同級(jí)目錄)
重啟 Xcode
完成安裝
使用
:run
: xcode 代碼運(yùn)行
:make
: 構(gòu)建 xcode 代碼
:xhelp
: 光標(biāo)位置快速幫助
:xccmd
: 執(zhí)行 xcode 菜單
? g
: 打印當(dāng)前行的位置
VimumVimum
是一款 Chrome
插件, 使用 vim 的模式概念讓我們可以脫離鼠標(biāo)訪(fǎng)問(wèn)瀏覽網(wǎng)頁(yè)
gg
: 跳轉(zhuǎn)到頁(yè)面頂部
G
: 跳轉(zhuǎn)到頁(yè)面底部
gi
: 激活搜索框
j
: 頁(yè)面向下滾動(dòng)
k
: 頁(yè)面向上滾動(dòng)
u
: 頁(yè)面向上翻頁(yè)
d
: 頁(yè)面向下翻頁(yè)
r
: 刷新當(dāng)前頁(yè)面
H
: 頁(yè)面回退到上一次歷史
L
: 頁(yè)面從歷史記錄中返回來(lái)
x
: 關(guān)閉頁(yè)面
X
: 恢復(fù)被關(guān)閉的頁(yè)面 (可多次重復(fù))
f
: 顯示頁(yè)面上各個(gè)點(diǎn)擊點(diǎn)的鏈接, 可以在當(dāng)前頁(yè)打開(kāi)
F
: 顯示頁(yè)面上各個(gè)點(diǎn)擊點(diǎn)的鏈接, 在新頁(yè)面打開(kāi)
gt
: 向右側(cè)瀏覽下一個(gè) tab
gT
: 向左側(cè)瀏覽 tab
yf
: 拷貝頁(yè)面上顯示的鏈接
yy
: 拷貝當(dāng)前網(wǎng)頁(yè)的鏈接
yt
: 復(fù)制當(dāng)前 tab
v
: 進(jìn)入選擇模式, 可選擇文本, 第一次按下時(shí)會(huì)進(jìn)入 creat mode
, 選中起點(diǎn)后再次按下 v
將啟用選擇模式, 然后按下 y
來(lái)進(jìn)行復(fù)制. 如果需要再次進(jìn)入
creat mode
, 可使用 c
按鍵. 如果在復(fù)制中要改變復(fù)制區(qū)域的起點(diǎn), 可以使用 o
按鍵, 或者在使用 /
進(jìn)行搜索確定焦點(diǎn)后進(jìn)行 v
選擇操作.
在選擇模式中可使用 w
, b
, h
, j
, k
, l
, e
, $
來(lái)進(jìn)行移動(dòng)
V
: 進(jìn)入行選擇模式, 可批量選擇多行文本
o
: 鍵入搜索內(nèi)容, 可在當(dāng)前頁(yè)面顯示歷史記錄或打開(kāi)網(wǎng)頁(yè)鏈接或搜索新內(nèi)容
O
: 兼容搜索內(nèi)容, 在新頁(yè)面給出與 o 鍵相同的結(jié)果
b
: 搜索書(shū)簽, 并在當(dāng)前頁(yè)面打開(kāi)
B
: 搜索書(shū)簽, 并在新頁(yè)面打開(kāi)
T
: 在已打開(kāi)的 tab 中進(jìn)行搜索
/
: 搜索當(dāng)前頁(yè)面值, 使用 ? F
進(jìn)行也頁(yè)面搜索, /
不能搜索中文
n
: 選中下一個(gè)搜索結(jié)果
N
: 選中上一個(gè)搜索結(jié)果
Vimari如果你正在使用 Safari
, 但是也想在瀏覽器中使用 vim 的操作, 那么 Vimari
就很適合你了, 因?yàn)?Vimum
不支持 Safari
, 因此 Vimari
就誕生出來(lái)了,
雖然沒(méi)有 Vimum
功能那么強(qiáng)大, 但是基本的瀏覽操作倒是都覆蓋了
f
: 觸發(fā)跳轉(zhuǎn)
F
: 觸發(fā)跳轉(zhuǎn) (新 tab 中打開(kāi)鏈接)
h/j/k/l
: 移動(dòng)
u
: 向上翻頁(yè)
d
: 向下翻頁(yè)
gg
: 跳轉(zhuǎn)到頁(yè)面頂部
G
: 跳轉(zhuǎn)到頁(yè)面底部
gi
: 跳轉(zhuǎn)到第一個(gè)輸入處
H
: 回到前一個(gè)歷史頁(yè)面
L
: 回到后一個(gè)歷史頁(yè)面
r
: 重載頁(yè)面
w
: 下一個(gè) tab
q
: 上一個(gè) tab
x
: 關(guān)閉當(dāng)前 tab
t
: 開(kāi)啟新 tab
其他插件vim 豐富的插件生態(tài)是其一大特色, 本文只是起到拋磚引玉的功能, 更多實(shí)用的插件有待讀者的發(fā)現(xiàn). 以下列舉了筆者常用的插件.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 "============= File Management ============= Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " 模糊搜索 Plug 'junegunn/fzf.vim' " 模糊搜索 Plug 'embear/vim-localvimrc' " 用于針對(duì)工程設(shè)置 vimrc " ============= Edit =========== Plug 'ycm-core/YouCompleteMe' " 補(bǔ)全插件 Plug 'SirVer/ultisnips' " 自定義某些片段 Plug 'ludovicchabant/vim-gutentags' " 根據(jù) ctags 或 gtags 生成 tags 進(jìn)行使用, 自動(dòng)管理 Plug 'skywind3000/gutentags_plus' " 提供 Plug 'Shougo/echodoc.vim' Plug 'lyokha/vim-xkbswitch', {'as': 'xkbswitch'} " 返回到 normal 模式時(shí)快速切換為英文輸入法 Plug 'dense-analysis/ale' " 提示語(yǔ)法錯(cuò)誤 Plug 'easymotion/vim-easymotion' " 空格任意跳轉(zhuǎn) Plug 'bronson/vim-visual-star-search' Plug 'jiangmiao/auto-pairs' " 匹配括號(hào) Plug 'dhruvasagar/vim-table-mode' " 自動(dòng)表格, 使用 `\tm` 就進(jìn)入了表格模式, 會(huì)進(jìn)行自動(dòng)對(duì)齊 Plug 'godlygeek/tabular' " 文本對(duì)齊, 使用:Tabularize /= 可以等號(hào)對(duì)齊多行 Plug 'terryma/vim-multiple-cursors' " 多行文本操作 Plug 'tpope/vim-commentary' " 快速注釋, gcc Plug 'tpope/vim-repeat' " 支持重復(fù) Plug 'tpope/vim-surround' " 包圍符號(hào) Plug 'tpope/vim-unimpaired' " ============= Appearance ============ Plug 'joshdick/onedark.vim' Plug 'ap/vim-css-color' " 顯示 css 顏色 Plug 'machakann/vim-highlightedyank' " 使 yank 的文檔半透明高亮 Plug 'mhinz/vim-signify' " 顯示當(dāng)前行的 git 狀態(tài) Plug 'Yggdroot/indentLine' " 顯示縮進(jìn)線(xiàn) Plug 'itchyny/lightline.vim' " 顯示底部導(dǎo)航欄 "============== Function ============== Plug 'majutsushi/tagbar' " 顯示文檔的層級(jí) Plug 'qpkorr/vim-renamer' " 批量修改文件的神器, 使用:Ren 進(jìn)行編輯與保存, 完成后退出即可 Plug 'Chiel92/vim-autoformat' " 自動(dòng)格式化文檔 Plug 'skywind3000/asyncrun.vim' " 異步執(zhí)行 Plug 'tpope/vim-fugitive' " git 插件 Plug 'jiazhoulvke/jianfan' " 簡(jiǎn)繁轉(zhuǎn)換 Tcn, Scn Plug 'simnalamburt/vim-mundo' " 顯示修改歷史 "============== Language ============== Plug 'plasticboy/vim-markdown' " markdown 增強(qiáng)插件 Plug 'jszakmeister/markdown2ctags' " markdown 層級(jí)顯示 Plug 'iamcco/markdown-preview.nvim', {'do': 'cd app & yarn install'} " Markdown 實(shí)時(shí)預(yù)覽
實(shí)際上以上所列出的插件很多僅由百余行的文件構(gòu)成, 所以如果一些插件不能滿(mǎn)足需求的話(huà)完全可以按照自己的想法寫(xiě)出一個(gè)適合自己的插件. 想法最重要, 做一件事只要有了想法就成功了 80%.
最后我的 vim 配置倉(cāng)庫(kù): hanleylee/dotvim
本文作者 Hanley Lee, 首發(fā)于 閃耀旅途 , 如果對(duì)本文比較認(rèn)可, 歡迎 Follow