重溫vim的配置:支援go

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

參考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

  1. 這個外掛程式很有用,不需要重新安裝,已經存在。游標停留在某函數或變數上,輸入:Ack,會自動全域搜尋調用處。
  2. 常用的命令:
?    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支援

  1. 外掛程式vim-go已經存在,但需要運行GoInstallBinaries,下載一些bin檔案。前提是配置好$GOBIN,參考Go環境安裝
  2. cd ~退出至home下,一定要在home下,否則後面會報錯。
  3. 終端vim隨便開啟一個檔案,輸入:GoInstallBinaries,斷行符號開始下載
  4. 如果需要更新,輸入:GoUpdateBinaries
  5. 增加配置,讓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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.