VIM 配置

01. VIM 配置
02. Neovim 配置
03. IdeaVim 進階配置
04. VsVim 配置

前言

請知悉:
在 gvim 中:
.vimrc == _vimrc
~/.vim == $VIM/vimfiles(其中酪术,$VIM 為用戶本地 Vim 安裝目錄)

基礎(chǔ)配置

" change leader \ to,this will endup f{Char} a little slower.
let mapleader=';'

" no backup (not producing ~ file)
set noundofile
set nobackup
set noswapfile

"  real time search result shown
set incsearch  
" 搜索到文件兩端時不重新搜索  
set nowrapscan  

" Allow to switch buffers without saving
set hidden

" encoding setting
set enc=utf-8  
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 

" auto complete brackets
inoremap {<CR> {<C-o>o}<C-o>O
inoremap ( ()<ESC>i
inoremap < <><ESC>i
inoremap " ""<ESC>i
inoremap ' ''<ESC>i

更改 colorscheme

  1. 到網(wǎng)上下載一個 scheme,推薦:vivify
scheme
  1. 將上一步下載的主題的 .vim 文件放入到路徑:~/.vim/colors(windows放入到:$VIM/vimfiles/colors)

  2. 在.vimrc(_vimrc)中添加:colorscheme SolarizedDark,然后重啟 vim 或者直接輸入 :source $MYVIMRC

當然更簡單的方法就是使用包管理插件,但謹記設(shè)置主題是必須在主題插件加載完后(即在 plug#end() 后面進行設(shè)置才行)
比如股淡,這里我們下在一個主題插件 vim-hybrid-material,其具體配置如下所示:

call plug#begin(g:plugins_path)
" ...
Plug 'kristijanhusak/vim-hybrid-material'
call plug#end()

" 只有在包管理插件完成后,才表示插件安裝完成挽牢,這時才能對下載的主題進行獲取設(shè)置
if (has("nvim"))
    "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
    set background=dark
    colorscheme hybrid_reverse
    " making functions and language controls to be bolded
    let g:enable_bold_font = 1
    " make comments to be in italic
    let g:enable_italic_font = 1
    " make background transparent
    " let g:hybrid_transparent_background = 1
    let g:airline_theme = "hybrid"
endif

"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
  set termguicolors
endif 

gvim 安裝 vundle

  1. 下載:
git clone https://github.com/VundleVim/Vundle.vim.git $VIM/vimfiles/bundle/Vundle.vim

2.配置

function IsWin32()
    return has('win32')
endfunction

function IsWin32Unix()
    return has('win32unix')
endfunction

function IsUnix()
    return has('unix')
endfunction

function IsMac()
    return has('macunix')
endfunction


" vundle configurations
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
if IsWin32()
    set rtp+=$VIM/vimfiles/bundle/Vundle.vim
    call vundle#begin('$VIM/vimfiles/bundle/')
elseif IsUnix() || IsWin32Unix() || IsMac()
    set rtp+=~/.vim/bundle/Vundle.vim
    call vundle#begin()
endif

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
 Plugin 'VundleVim/Vundle.vim'
" add plugin here


 " All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required 
  1. 配置 Git,將Git的路徑設(shè)置到環(huán)境變量中摊求,這樣禽拔,vundle 會自動使用 Git 下載相應的插件進行安裝。
    詳情查看:Vundle for Windows

gvim 安裝 vim-plug

  1. 下載:下載 plug.vim室叉,并放置到安裝目錄的$VIM/vimfiles/autoload

  2. 配置:

" plug-vim configurations
call plug#begin('~/.vim/plugged')
" -------------------------------------------------------------------------
" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
" -------------------------------------------------------------------------
" Initialize plugin system
call plug#end()
  1. 命令:如下表所示:
命令 描述
PlugInstall [name ...] [#threads] 安裝插件
PlugUpdate [name ...] [#threads] 安裝或更新插件
PlugClean[!] 移除插件
PlugUpgrade 更新 vim-plug
PlugStatus 檢查插件狀態(tài)
PlugDiff 檢測插件更新的內(nèi)容
PlugSnapshot[!] [output path] 為當前插件狀態(tài)生成一個快照
  1. Plug命令選項:如下表所示:
命令 描述
branch/tag/commit 使用倉庫的對應 branch/tag/commit 版本
rtp 包含 Vim 插件的子目錄
dir 為插件自定義存儲目錄
as 為插件定義別名
do 安裝或更新插件鉤子(在安裝或更新插件后睹栖,自動調(diào)用鉤子函數(shù))
on 按需加載插件
for 按文件類型加載插件
frozen 除非明確指定,否則不更新插件

按需加載例子:

" NERD tree 插件會在首次使用 NERDTreeToggle 命令時進行加載
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }

" 多個命令
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }

" 當文件類型為 clojure 時茧痕,加載插件
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" 多種文件類型
Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }

" 當首次執(zhí)行 Vader 命令野来,且文件類型為 vader 時,加載插件
Plug 'junegunn/vader.vim',  { 'on': 'Vader', 'for': 'vader' }

" 插件按需加載后執(zhí)行特定代碼
Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
autocmd! User goyo.vim echom 'Goyo is now loaded!'

插件安裝

  • Vundle
    插件管理器踪旷,安裝及配置請參考上文

  • vim-plug
    插件管理器曼氛,安裝及配置請參考上文

  • NERDTree
    文件系統(tǒng)瀏覽器

nmap wm :NERDTreeToggle<CR>
let NERDTreeWinPos='left'
let NERDTreeWinSize=30

一些好用點:

命令/按鍵 功能
o 打開文件,相當于 <CR>
go 打開文件令野,但光標還是留在 NERDTree
x 關(guān)閉當前節(jié)點
X 迭代關(guān)閉當前節(jié)點及子節(jié)點
q 關(guān)閉 NERDTree 窗口
p 跳到當前頂層根節(jié)點
P 跳到最頂層根節(jié)點
I 顯示/隱藏 不可見文件
A 最大化/最小化 窗口
R/r 刷新所在節(jié)點及其子節(jié)點/當前目錄(增加/刪除文件···)
m 文件操作提示(可以進行文件/文件夾創(chuàng)建舀患,刪除,移動)
刪除文件快捷操作 選中气破,mdy
<C-J>/<C-K> 同節(jié)點移動(忽略子節(jié)點)

更多 NERDTree 操作聊浅,請查看:KeyMappings

  • CtrlSF:替換為 fzf
    全局文件搜索 Vim 插件。類似 ag,awk,ag,vimgrep······

配置:

if executable('ag')
    let g:ctrlsf_ackprg = 'ag'
endif
let g:ctrlsf_case_sensitive = 'smart'
let g:ctrlsf_default_root = 'project'
let g:ctrlsf_default_view_mode = 'normal'
let g:ctrlsf_position = 'left'
let g:ctrlsf_winsize = '30%'

nnoremap <C-f> :CtrlSF<Space>
inoremap <C-f> <ESC>:CtrlSF<Space>
" visiual and select mode
vnoremap <C-f> "1y:CtrlSF<Space><C-R>1 
" visiual mode
" xnoremap <C-f> :CtrlSF<Space> 
" command line mode
cnoremap <C-f> CtrlSF 

常用命令:

命令/按鍵 功能
:CtrlSF [pattern] 啟動搜索
:CtrlSFOpen 重新打開先前關(guān)閉的搜索窗口
M quickfix 形式展示搜索結(jié)果
<C-J> 移動到下一個匹配處
<C-K> 移動到上一個匹配處
p 打開預覽窗口
P 打開預覽窗口,并將焦點移動到預覽窗口
t 用標簽(tab)打開
T 用標簽(tab)打開狗超,但是保留焦點還在 CtrlSF 中
O Enter 一樣弹澎,但是會保留 CtrlSF 窗口
  • CtrlP(改成 fzf):Vim 的模糊搜索工具,支持文件努咐,緩沖區(qū)苦蒿,MRU(Most Recently Used)文件和標簽等的搜索,也支持通過正則表達式搜索(Ctrl-r進行切換)
" Change the default mapping and the default command to invoke CtrlP
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
" set local working directory:current file
let g:ctrlp_working_path_mode = 'ra'
" exclusions
set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe  " Windows
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/]\.(git|hg|svn)$',
  \ 'file': '\v\.(exe|so|dll)$',
  \ 'link': 'some_bad_symbolic_links',
  \ }
" let g:ctrlp_user_command = ['.git/', 'git ls-files --cached --others  --exclude-standard %s']
" The Silver Searcher
if executable('ag')
  " Use ag over grep
let g:ctrlp_user_command = ['ag','ag %s -i --nocolor --nogroup --hidden
            \ --ignore .git
            \ --ignore .svn
            \ --ignore .hg
            \ --ignore .DS_Store
            \ --ignore "**/*.pyc"
            \ -g ""' ]
endif 

注意:上面配置中讓 CtrlP 使用外部的掃描工具 ag(the Silver Searcher)渗稍,使得其搜素速度有了質(zhì)的提升 :).

一些好用點:

命令/按鍵 功能
:CtrlP/:CtrlP [starting-directory] 啟動 CtrlP
<C-d> 切換到僅搜索文件名而不是完整路徑
<F5> 刷新緩存(更新新增文件佩迟,刪除文件···)
<c-r> 切換為正則搜索
<c-t> or <c-v>, <c-x> 新窗口打開文件

好用點:

命令/按鍵 功能
<leader><leader>w 從光標位置起,往 單詞 之間移動光標
<leader><leader>b 從光標位置起竿屹,往 單詞 之間移動光標
<leader><leader>s{char} 全局搜索指定 字符
<leader><leader>f{char} 從光標位置起报强,往 搜索指定 字符
  • Syntastic
    語法檢測,Syntastic 支持大多數(shù)常見語言語法檢測拱燃,要求是語法檢測器應該配置到系統(tǒng)環(huán)境變量$PATH中秉溉。

可以通過:SyntasticInfo查看當前語法檢測器是否正確以及是否能正常工作,可以通過在 .vimrc/_vimrc 中指定相應類型的文件對應的語法檢測器:

let g:syntastic_<filetype>_checkers = ['<checker-name>']

Syntastic 基本配置如下:

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
  • surround.vim
    快速的為字符串增加/刪除/修改引號/括號或者HTML標簽
Mode 命令/按鍵 功能
Normal ys add a surrounding
Normal yS add a surrounding and place the surrounded text on a new line + indent it
Normal yss add a surrounding to the whole line
Normal ySs add a surrounding to the whole line, place it on a new line + indent
Normal cs change a surrounding
Normal ds delete a surrounding
Visual s add a surrounding
Visual S add a surroudning but place tex on new line + indent it
Insert <C-s> add a surrounding
Insert <C-s><C-s> add a new line + surrouding + indent

好用命令:

命令/按鍵 功能
單詞增加引號 ysiw"(add surrounding " in word)
2個單詞增加引號 ys2w" ( add surrounding " for 2 words
一行增加引號 yss"
刪除引號 ds" (delete surrounding "")
修改"為<html> cs"<html> ( change surrounding "" to <html></html>
visiual模式下碗誉,為當前選中字符增加引號 S"
  • vim-repeat:增強.重復執(zhí)行插件功能召嘶。
    安裝:
Plug 'tpope/vim-repeat'

vim-repeat 以默認支持插件:surround.vim,如果還想支持其他插件功能哮缺,則進行如下配置:

silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
  • NERD Commenter
    快速注釋代碼插件弄跌,根據(jù)文件類型,自動選擇合適的注釋風格尝苇。
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
 let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
 let g:NERDCustomDelimiters = { 'java': { 'left': '//'} }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1

基礎(chǔ)命令:

命令/按鍵 功能
[count]<leader>cc Comment out the current line or text selected in visual mode
[count]<leader>cu Uncommenets the selected line(s)
  • markdown-preview.vim
    vim 添加 Markdown 支持铛只。安裝配置成功該插件后,打開 markdown 文件糠溜,輸入 :MarkdownPreview淳玩,則會自動彈出瀏覽器進行實時預覽。

Usage:

 " open preview window in markdown buffer
MarkdownPreview
   
" close the preview window and server
MarkdownPreviewStop

Default Setting:

" path to the chrome or the command to open chrome(or other modern browsers)
let g:mkdp_path_to_chrome = 'C:\Program Files (x86)\Google\Chrome\Application\chrome'

" set to 1, the vim will open the preview window once enter the markdown
" buffer
let g:mkdp_auto_start = 0

" set to 1, the vim will auto open preview window when you edit the
" markdown file
let g:mkdp_auto_open = 0

" set to 1, the vim will auto close current preview window when change
" from markdown buffer to another buffer
let g:mkdp_auto_close = 1

" set to 1, the vim will just refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
let g:mkdp_refresh_slow = 0

" set to 1, the MarkdownPreview command can be use for all files,
" by default it just can be use in markdown file
let g:mkdp_command_for_global = 0

nmap <silent> <F8> <Plug>MarkdownPreview        " for normal mode
imap <silent> <F8> <Plug>MarkdownPreview        " for insert mode
nmap <silent> <F9> <Plug>StopMarkdownPreview    " for normal mode
imap <silent> <F9> <Plug>StopMarkdownPreview    " for insert mode

注意: 該插件要求 vim 支持 python诵冒,所以要確保 vim 是支持 python凯肋,并且電腦要安裝 python2 或 python3∑觯可以在 vim 內(nèi)輸入 :echo has('python') || has('python3')侮东,返回 1 表示 vim 已經(jīng)支持 python。

Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install_sync() },'for':['markdown','vim-plug']} 

" set to 1, nvim will open the preview window after entering the markdown buffer
" default: 0
let g:mkdp_auto_start = 0

" set to 1, the nvim will auto close current preview window when change
" from markdown buffer to another buffer
" default: 1
let g:mkdp_auto_close = 1

" set to 1, the vim will refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
" default: 0
let g:mkdp_refresh_slow = 0

" set to 1, the MarkdownPreview command can be use for all files,
" by default it can be use in markdown file
" default: 0
let g:mkdp_command_for_global = 0

" set to 1, preview server available to others in your network
" by default, the server listens on localhost (127.0.0.1)
" default: 0
let g:mkdp_open_to_the_world = 0

" use custom IP to open preview page
" useful when you work in remote vim and preview on local browser
" more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9
" default empty
let g:mkdp_open_ip = ''

" specify browser to open preview page
" default: ''
let g:mkdp_browser = g:chrome

" set to 1, echo preview page url in command line when open preview page
" default is 0
let g:mkdp_echo_preview_url = 0

" a custom vim function name to open preview page
" this function will receive url as param
" default is empty
let g:mkdp_browserfunc = ''

" options for markdown render
" mkit: markdown-it options for render
" katex: katex options for math
" uml: markdown-it-plantuml options
" maid: mermaid options
" disable_sync_scroll: if disable sync scroll, default 0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
"   middle: mean the cursor position alway show at the middle of the preview page
"   top: mean the vim top viewport alway show at the top of the preview page
"   relative: mean the cursor position alway show at the relative positon of the preview page
" hide_yaml_meta: if hide yaml metadata, default is 1
" sequence_diagrams: js-sequence-diagrams options
let g:mkdp_preview_options = {
    \ 'mkit': {},
    \ 'katex': {},
    \ 'uml': {},
    \ 'maid': {},
    \ 'disable_sync_scroll': 0,
    \ 'sync_scroll_type': 'middle',
    \ 'hide_yaml_meta': 1,
    \ 'sequence_diagrams': {}
    \ }

" use a custom markdown style must be absolute path
let g:mkdp_markdown_css = ''

" use a custom highlight style must absolute path
let g:mkdp_highlight_css = ''

" use a custom port to start server or random for empty
let g:mkdp_port = ''

" preview page title
" ${name} will be replace with the file name
let g:mkdp_page_title = '「${name}」'

:在本人 Win10 系統(tǒng)上豹芯,腳本配置完后無法打開瀏覽器悄雅,還需手動在 Neovim 上執(zhí)行:call mkdp#util#install()

  • vim-airline
    這是一款狀態(tài)欄增強插件,可以讓你的 Vim 狀態(tài)欄非常的美觀铁蹈,同時包括了buffer顯示條擴展smart tab line以及集成了一些插件宽闲。
    vim-airline 其實是 powerline 的 copy,它相比 powerline 有幾個好處:它是純 vim script,powerline 則用到 python容诬;它簡單娩梨,速度比 powerline 快。

如果還想要更多主題樣式览徒,還需需要下載:vim-airline-themes

具體主題 screenshot 可以查看:Screenshots

  • delimitMate (與 vim-multiple-cursors 有沖突狈定,在多光標模式下,輸入"會生成<Plug>delimitMate习蓬,暫時沒有找到解決方法纽什,故暫不使用,改用 auto-pairs
    提供引號躲叼,大括號芦缰,括號自動補全的 Vim 插件。

配置:

inoremap {<CR> {<CR>}<C-o>O
" Use this option to tell delimitMate which characters should be considered
" matching pairs. Read |delimitMateAutoClose| for details.
let delimitMate_matchpairs = "(:),[:],{:},<:>"
au FileType vim,html let b:delimitMate_matchpairs = "(:),[:],{:},<:>"

更多詳細配置枫慷,請查看:doc

  • auto-pairs:自動補全/刪除括號

  • fcitx:輸入法狀態(tài)自動切換

  • vim-json:A better JSON for Vim

  • vim-css3-syntax:css3 語法支持

  • vim-coloresque:為 Vim 提供 css/less/sass/html 顏色預覽

  • vim-javascript:為 Vim 提供縮進和 JavaScript 語法支持

  • emmet-vim:html 擴展工具
    例子:
    1)新建一個html文件后,輸入html:5,然后按<Ctrl+y+,>(速度要快點),即可生成:

<!DOCTYPE html>
 <html lang="en">
 <head>
   <meta charset="UTF-8">
    <title></title>
 </head>
 <body>

 </body>
 </html>

2)輸入p.class#id让蕾,然后按<Ctrl+y+,>,則會生成:

<p id="id" class="class"></p>

3)輸入h1{foo}流礁, 然后按<Ctrl+y+,>涕俗,則會生成:

<h1>foo</h1>

4)輸入h1+h2, 然后按<Ctrl+y+,>,則會生成:

   <h1></h1>
   <h2></h2>

5)輸入img^a, 然后按<Ctrl+y+,>神帅,則會生成:

   <img src="" alt="">
   <a href=""></a>

6)輸入h1>h2, 然后按<Ctrl+y+,>,則會生成:

   <h1>
       <h2></h2>
   </h1>

7)輸入(.foo>h1)萌抵,相當于輸入div.foo>h1找御,然后按<Ctrl+y+,>,則會生成:

   <div class="foo">
       <h1></h1>
   </div>

8)輸入ul>li*3绍填, 然后后按<Ctrl+y+,>霎桅,則會生成:

   <ul>
       <li></li>
       <li></li>
       <li></li>
   </ul>

9)輸入ul>li.item$*3,然后后按<Ctrl+y+,>讨永,則會生成:

   <ul>
       <li class="item1"></li>
       <li class="item2"></li>
       <li class="item3"></li>
   </ul>

更多用法滔驶,請參考:TUTORIAL
emmet-vim 的基本規(guī)則如下:

1. E 代表HTML標簽:<E></E>
2. E#id 代表標簽E有id屬性:<E id=""></E>
3. E.class 代表E有class屬性:<E class=""></E>
4. E[attr=foo] 代表某個特定屬性:<E foo=""></E>
5. E{info} 代表標簽E包含的內(nèi)容是info:<E>info</E>
6. E>N 代表N是E的子元素:<E><N></N></E>
7. E+N 代表N是E的同級元素:<E></E><N></N>
8. E^N 代表N是E的同級元素:<E></E><N></N>
" markdown table improvment
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }
" 配置快捷鍵
nnoremap <Leader>tm :TableModeToggle<CR>
" markdown-compatible tables
let g:table_mode_corner='|'

function! s:isAtStartOfLine(mapping)
  let text_before_cursor = getline('.')[0 : col('.')-1]
  let mapping_pattern = '\V' . escape(a:mapping, '\')
  let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\')
  return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$')
endfunction
" 插入模式下,按 || 使能插件
inoreabbrev <expr> <bar><bar>
          \ <SID>isAtStartOfLine('\|\|') ?
          \ '<c-o>:TableModeEnable<cr><bar><space><bar><left><left>' : '<bar><bar>'
" 插入模式下卿闹,按 __ 失能插件
inoreabbrev <expr> __
          \ <SID>isAtStartOfLine('__') ?
          \ '<c-o>:silent! TableModeDisable<cr>' : '__'

操作方法:
1)首先揭糕,先啟動插件::TableModeToggle,或直接使用快捷鍵:<Leader>tm
2)在插入模式下锻霎,輸入一個|著角,再輸入列名,再輸入另一個|旋恼,此時 vim-table-mode 會自動進行格式化吏口,如下圖所示:

step 1

3)在第二行(無需離開插入模式),輸入兩次|。插件會自動創(chuàng)建一條水平線产徊,如下圖所示:

step 2

4)后續(xù)輸入內(nèi)容時昂勒,每次輸入|后,插件就會自動依據(jù)內(nèi)容大小自動調(diào)整格式舟铜,如下圖所示:

step 3

5)表格完成后戈盈,就可以禁止插件功能::TableModeDisable,或使用快捷鍵:<Leader>tm深滚,最簡單的是直接在插入模式下輸入:兩個_奕谭,并切換到 normal 模式即可。

Plug 'terryma/vim-multiple-cursors'
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)normal / visual 模式下:

快捷鍵 功能
<C-n> 進入多光標選擇模式
<C-x> 忽略當前文本痴荐,跳到下一位置
<C-p> 忽略當前文本血柳,跳到上一位置
<A-n> 直接選擇所有符合的文本
g<C-n> 忽略單詞邊界,進行選中
g<A-n> 忽略單詞邊界生兆,選中所有

當文本選中后难捌,就可以使用在 visual 模式下的任何命令進行修改,比如:c, s, I, A都可以直接進行編輯鸦难。
你也可以在選中后根吁,按下 v,然后就可以直接使用 normal 模式下的命令進行操作合蔽。

命令 描述
Limelight [0.0 ~1.0] 打開 [Limelight]
Limelight! 關(guān)閉 [Limelight]
Limelight!! [0.0 ~ 1.0] 切換 [Limelight]

配置:

" Hyperfocus-writing in Vim
Plug 'junegunn/limelight.vim'
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240

" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'

" Default: 0.5
let g:limelight_default_coefficient = 0.7

" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 1

" Beginning/end of paragraph
"   When there's no empty line between the paragraphs
"   and each paragraph starts with indentation
let g:limelight_bop = '^\s'
let g:limelight_eop = '\ze\n^\s'

" Highlighting priority (default: 10)
"   Set it to -1 not to overrule hlsearch
let g:limelight_priority = -1
  • goyo.vim:為 Vim 提供無干擾編輯击敌。
    使用方法:
命令 描述
:Goyo 切換 Goyo
:Goyo [dimension] 打開或調(diào)整尺寸
:Goyo! 關(guān)閉 Goyo

配置:

" distraction free writing mode
Plug 'junegunn/goyo.vim' 
let g:gyo_width=80
let g:goyo_height='85%'
let g:goyo_linenr=0

nmap <Leader>ll :Goyo<CR>
xmap <Leader>ll :Goyo<CR>

"進入goyo模式后自動觸發(fā)limelight,退出后則關(guān)閉
function! s:goyo_enter()
  if executable('tmux') && strlen($TMUX)
    silent !tmux set status off
    silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
  endif
  Limelight
  " ...
endfunction

function! s:goyo_leave()
  if executable('tmux') && strlen($TMUX)
    silent !tmux set status on
    silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
  endif
  Limelight!
  " ...
endfunction

autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()

更多配置方法,請查看:Customization

  • tabular:文本對齊工具
    使用方法::Tabularize拴事,其格式為:
[對齊方式[此方式后添加的空格數(shù)量]]

:對齊方式 左l沃斤、右r、中c刃宵。需要與前面用/隔開衡瓶。

例子:
1)將以下文本以逗號對齊::Tabularize /,

:Tabularize /,

2)將以下代碼的注釋進行對齊::Tabularize /\/\/

:Tabularize ///

3)將以下文本以冒號進行分割,并將第一部分內(nèi)容(第一個冒號前)的所有文本右對齊牲证,并添加一個空格哮针;將中間部分內(nèi)容居中對齊,并添加一個空格坦袍;最后將剩余部分文本左對齊十厢,但不添加空格::Tabularize /:/r1c1l0

:Tabularize ////r1c1l0
  • far.vim:文本查找和替換插件
    使用方法:
:Far foo bar **/*.py
:Fardo`

命令講解:

命令 描述
:Far {pattern} {replace-with} {file-mask} [params] 查找文本
:Fardo [params] 進行文本替換
:F {pattern} {file-mask} [params] 只進行文本查找

例子:
1)查找當前文件所在目錄的所有含有main的.py`文件:

:F main **/*.py

2)查找當前文件所在目錄的所有含有main的.py文件,并替換成"MAIN"`:

" 查找
:Far main MAIN **/*.py
" 替換
:Fardo
" do not highlight conceal color(not background)
let g:indentLine_setColors = 1
" customize conceal color
" Vim
let g:indentLine_color_term = 239

" GVim
let g:indentLine_color_gui = '#A4E57E'

" none X terminal
let g:indentLine_color_tty_light = 7 " (default: 4)
let g:indentLine_color_dark = 1 " (default: 2)

" Background (Vim, GVim)
let g:indentLine_bgcolor_term = 202

" let g:indentLine_char = 'c'
" let g:indentLine_char_list = ['|', '|', '┆', '┊']
" change conceal behaviour
let g:indentLine_concealcursor = 'inc'
let g:indentLine_conceallevel = 2

  • tagbar:顯示代碼標簽插件
    安裝:
    1)Vim 版本:>= 7.3.1058
    2)由于 tagbar 本身并不生成標簽文件(tags file),因此我們需要安裝標簽文件生成工具键闺,如 Exuberant Ctags 5.5 或者 Universal Ctags(推薦)
    3)安裝并配置:
Plug 'majutsushi/tagbar', { 'on': 'TagbarOpenAutoClose' }

" set ctags bin path
let g:tagbar_ctags_bin = 'D:\config\ctags\ctags.exe'
" let g:tagbar_ctags_bin = '/usr/bin/ctags'

map <silent> <leader>tb :TagbarOpenAutoClose<CR>
let g:SignatureMap = {
        \ 'Leader'             :  "m",
        \ 'GotoNextLineByPos'  :  "]<Leader>", " jump to next mark
        \ 'GotoPrevLineByPos'  :  "[<Leader>", " jump to prev mark
        \ 'ListBufferMarks'    :  "m/",        " show all marks
        \ }

更多自定義配置寿烟,請查看:Customization Refer

  • undotree:為 Vim 提供可視化的歷史記錄。對于大多數(shù)編輯器來說辛燥,當修改歷史為:A -> B -> A -> C 時筛武,最終的結(jié)果就是:A -> C缝其。但 Vim 的歷史記錄并不是上述的線性記錄,而是采用類似樹形的結(jié)構(gòu)進行記錄徘六。因此内边,A -> B -> A -> C 的全部修改變更都會被保留。借助于 undotree 該插件待锈,我們就可以直接查看修改歷史漠其,并選擇需要的記錄進行回退。
    配置:
nnoremap <Leader>ud :UndotreeToggle<CR>
" 持久化歷史記錄
if has("persistent_undo")
    set undodir=$HOME."/.undodir"
    set undofile
endif

在歷史記錄可視化界面中:

Markers Description
> number < 表示當前狀態(tài)
{ number } 表示下一個回退狀態(tài)(redo)
[ number ] 表示最新狀態(tài)
s 表示保存狀態(tài)
S 表示最新保存狀態(tài)
  • fzf.vim:在 Vim 中使用 fzf (模糊搜索)插件竿音。

內(nèi)置命令:以下只列舉部分常用命令

命令 列舉
Files [PATH] 遞歸搜索 PATH 目錄(默認當前目錄)和屎,類似:FZF
Commands 列舉所有命令
Lines [QUERY] 搜索緩沖區(qū)行內(nèi)容
BLines [QUERY] 搜索當前緩沖區(qū)行內(nèi)容
Ag [PATTERN] ag搜索結(jié)果(ALT-A選擇全部,ALT-D取消所有)
Rg [PATTERN] rg 搜索結(jié)果(ALT-A選擇全部春瞬,ALT-D取消所有 )
History 列舉打開的文件歷史記錄
History: 列舉執(zhí)行的命令歷史記錄
History/ 列舉執(zhí)行的搜索歷史記錄
Marks 搜索標記
Colors 搜索主題
Buffers 搜索緩沖區(qū)
Tags [QUERY] 搜索項目 Tags(ctags -R
BTags [QUERY] 搜索當前項目 Tags(ctags -R
Maps 列舉 normal 模式下的按鍵映射
GFiles [OPTS] 列舉 Git 文件(git ls-files
GFiles? 列舉 Git 文件(git status
Commits 列舉 Git commits(要求安裝:fugitive.vim
BCommits 列舉當前緩沖區(qū)的 Git commits

:在搜索到所需文件后柴信,按住CTRL-T / CTRL-X /CTRL-V 可以在新標簽 / 水平分割 / 垂直分割 上打開新文件。

安裝及配置:

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

if has('nvim') || has('gui_running')
  let $FZF_DEFAULT_OPTS .= ' --inline-info'
endif

" Hide statusline of terminal buffer
autocmd! FileType fzf
autocmd  FileType fzf set laststatus=0 noshowmode noruler
  \| autocmd BufLeave <buffer> set laststatus=2 showmode ruler

" In Neovim, you can set up fzf window using a Vim command
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10new' }

let g:fzf_colors =
\ { 'fg':      ['fg', 'Normal'],
  \ 'bg':      ['bg', 'Normal'],
  \ 'hl':      ['fg', 'Comment'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', 'PreProc'],
  \ 'border':  ['fg', 'Ignore'],
  \ 'prompt':  ['fg', 'Conditional'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', 'Label'],
  \ 'header':  ['fg', 'Comment'] }

command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)
nnoremap <silent> <Leader>ag       :Ag <C-R><C-W><CR>
xnoremap <silent> <Leader>ag       y:Ag <C-R>"<CR>

參考

Turning vim into an IDE through vim plugins

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末宽气,一起剝皮案震驚了整個濱河市随常,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌萄涯,老刑警劉巖绪氛,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異涝影,居然都是意外死亡枣察,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門燃逻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來询件,“玉大人,你說我怎么就攤上這事唆樊。” “怎么了刻蟹?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵逗旁,是天一觀的道長。 經(jīng)常有香客問我舆瘪,道長片效,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任英古,我火速辦了婚禮淀衣,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘召调。我一直安慰自己膨桥,他們只是感情好蛮浑,可當我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著只嚣,像睡著了一般沮稚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上册舞,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天蕴掏,我揣著相機與錄音,去河邊找鬼调鲸。 笑死盛杰,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的藐石。 我是一名探鬼主播即供,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼贯钩!你這毒婦竟也來了募狂?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤角雷,失蹤者是張志新(化名)和其女友劉穎祸穷,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體勺三,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡雷滚,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了吗坚。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片祈远。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖商源,靈堂內(nèi)的尸體忽然破棺而出车份,到底是詐尸還是另有隱情,我是刑警寧澤牡彻,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布扫沼,位于F島的核電站,受9級特大地震影響庄吼,放射性物質(zhì)發(fā)生泄漏缎除。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一总寻、第九天 我趴在偏房一處隱蔽的房頂上張望器罐。 院中可真熱鬧,春花似錦渐行、人聲如沸轰坊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽衰倦。三九已至袒炉,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間樊零,已是汗流浹背我磁。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留驻襟,地道東北人夺艰。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像沉衣,于是被迫代替她去往敵國和親郁副。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,976評論 2 355

推薦閱讀更多精彩內(nèi)容