重温vim的配置:支持go

参考vimrc配置 ,先将基础的vimrc配置好。这是我之前的配置,但是使用中还是有些不方便,有些技能没有掌握好,于是又好好研究下vim的配置,增加了如下的插件配置,同时支持go。

我在上面的基础上手动增加了其余几个常用的插件

vim-easy-align:快速对齐

1.vim ~/.vim/bundles.vim,在末尾增加:

Bundle 'junegunn/vim-easy-align'

2.vim ~/.vim/vimrc,末尾增加:

vmap a (EasyAlign)
nmap a (EasyAlign)
if !exists('g:easy_align_delimiters')
      let g:easy_align_delimiters = {}
endif
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga (EasyAlign)
"
" " Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga (EasyAlign)

3.实例:
a. v模式,选择下面

let g:tagbar_left=1 
let g:tagbar_width=30
let g:tagbar_autofocus = 1 
let g:tagbar_sort = 0 
let g:tagbar_compact = 1 

b. 敲入ga,进入EasyAlign模式,敲入=,会按如下等号对齐显示:

let g:tagbar_left      = 1
let g:tagbar_width     = 30
let g:tagbar_autofocus = 1
let g:tagbar_sort      = 0
let 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=''
let g:multi_cursor_prev_key=''
let g:multi_cursor_skip_key=''
let g:multi_cursor_quit_key=''

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 = 1
let g:cpp_experimental_template_highlight = 1

Ack

  1. 这个插件很有用,不需要重新安装,已经存在。光标停留在某函数或变量上,输入:Ack,会自动全局搜索调用处。
  2. 常用的命令:
?    a quick summary of these keys, repeat to close
o    to open (same as Enter)
O    to open and close the quickfix window
go   to preview file, open but maintain focus on ack.vim results
t    to open in new tab
T    to open in new tab without moving to it
h    to open in horizontal split
H    to open in horizontal split, keeping focus on the results
v    to open in vertical split
gv   to open in vertical split, keeping focus on the results
q    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 = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let 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

你可能感兴趣的:(vim,vim,go,插件)