這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
參考vimrc配置 ,先將基礎的vimrc配置好。這是我之前的配置,但是使用中還是有些不方便,有些技能沒有掌握好,於是又好好研究下vim的配置,增加了如下的外掛程式配置,同時支援go。
我在上面的基礎上手動增加了其餘幾個常用的外掛程式
vim-easy-align:快速對齊
1.vim ~/.vim/bundles.vim,在末尾增加:
Bundle 'junegunn/vim-easy-align'
2.vim ~/.vim/vimrc,末尾增加:
vmap <Leader>a <Plug>(EasyAlign)nmap <Leader>a <Plug>(EasyAlign)if !exists('g:easy_align_delimiters') let g:easy_align_delimiters = {}endiflet g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }" Start interactive EasyAlign in visual mode (e.g. vipga)xmap ga <Plug>(EasyAlign)"" " Start interactive EasyAlign for a motion/text object (e.g. gaip)nmap ga <Plug>(EasyAlign)
3.執行個體:
a. v模式,選擇下面
let g:tagbar_left=1 let g:tagbar_width=30let g:tagbar_autofocus = 1 let g:tagbar_sort = 0 let g:tagbar_compact = 1
b. 敲入ga,進入EasyAlign模式,敲入=,會按如下等號對齊顯示:
let g:tagbar_left = 1let g:tagbar_width = 30let g:tagbar_autofocus = 1let g:tagbar_sort = 0let g:tagbar_compact = 1
更多的執行個體參考:https://github.com/junegunn/vim-easy-align
multiple-cursors:多游標操作
1.vim ~/.vim/bundles.vim,在末尾增加:
Bundle 'terryma/vim-multiple-cursors'
2.vim ~/.vim/vimrc,末尾增加:
" 多游標操作 let g:multi_cursor_use_default_mapping=0" Default mapping " ctrl+m 選中一個" ctrl+p 放棄一個, 回到上一個" ctrl+x 跳過當前選中, 選中下一個" esc 退出 let g:multi_cursor_next_key='<C-m>'let g:multi_cursor_prev_key='<C-p>'let g:multi_cursor_skip_key='<C-x>'let g:multi_cursor_quit_key='<Esc>'
3.執行個體:
a. 如下代碼中,游標停留再Println任何一個字母上,敲幾次ctrl+m,就會選中幾個Println
fmt.Println(url) fmt.Println(url.Scheme)fmt.Println(url.Opaque)fmt.Println(url.User)fmt.Println(url.Host)
b. 敲入c,輸入Print,選擇的Println會一塊替換成Print
fmt.Print(url) fmt.Print(url.Scheme)fmt.Print(url.Opaque)fmt.Print(url.User)fmt.Print(url.Host)
vim-cpp-enhanced-highlight:c++高亮
1.vim ~/.vim/bundles.vim,在末尾增加:
Plugin 'octol/vim-cpp-enhanced-highlight'
2.vim ~/.vim/vimrc,末尾增加:
let g:cpp_class_scope_highlight = 1let g:cpp_experimental_template_highlight = 1
Ack
- 這個外掛程式很有用,不需要重新安裝,已經存在。游標停留在某函數或變數上,輸入:Ack,會自動全域搜尋調用處。
- 常用的命令:
? a quick summary of these keys, repeat to closeo to open (same as Enter)O to open and close the quickfix windowgo to preview file, open but maintain focus on ack.vim resultst to open in new tabT to open in new tab without moving to ith to open in horizontal splitH to open in horizontal split, keeping focus on the resultsv to open in vertical splitgv to open in vertical split, keeping focus on the resultsq to close the quickfix window
go支援
- 外掛程式vim-go已經存在,但需要運行GoInstallBinaries,下載一些bin檔案。前提是配置好$GOBIN,參考Go環境安裝
- cd ~退出至home下,一定要在home下,否則後面會報錯。
- 終端vim隨便開啟一個檔案,輸入
:GoInstallBinaries,斷行符號開始下載
- 如果需要更新,輸入
:GoUpdateBinaries
- 增加配置,讓go的函數、方法、關鍵字等高亮顯示。
vim ~/.vim/vimrc,末尾增加:
let g:go_highlight_functions = 1let g:go_highlight_methods = 1let g:go_highlight_fields = 1let g:go_highlight_types = 1let g:go_highlight_operators = 1let g:go_highlight_build_constraints = 1
參考:
http://www.wklken.me/category/vim.html
http://vimawesome.com/
http://studygolang.com/articles/4777
https://github.com/yangyangwithgnu/use_vim_as_ide#4.1