vim--golang代码补全

时间:2022-07-09 01:41:35

我想说,我折腾了很久编辑器,试了九种办法

最后我只成功了一种

但我依然想就我混乱的逻辑做下整理

一、一开始,我试图入手ipad编码软件,大概9美金吧,叫Textastic。我试图用它的近亲来试验Textastic Mac Trial看看能否代码补全. 我安装了golang.tmbundle. 语法高亮和snips是有的。可惜没有补全。

二、我想,听说TextMate是Textastic Mac Trial的近亲,何不试试TextMate?于是下载安装

mkdir -p ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles
/Users/x/Library/Application Support/TextMate/Managed/Bundles>cd ~/Library/Application\ Support/Avian/Pristine\ Copy/Bundles
/Users/x/Library/Application Support/Avian/Pristine Copy/Bundles>git clone git://github.com/syscrusher/golang.tmbundle.git

同样安装了golang.tmbundle可惜按ESC如何敲打都呼唤不出TextMate代码补全。

三、我想了想,既然不会弄TextMate那就还是用回我的vim吧

  • 于是开始安装vim-go的插件,
Plug 'nsf/gocode', { 'rtp': 'vim', 'do': '~/.vim/bundle/gocode/vim/symlink.sh' }
Plug 'fatih/vim-go'
  • 之后,:GoInstallBinaries 由于众所周知的原因,golang包要特殊安装
go get -u golang.org/x/tools/cmd/guru
go get -u golang.org/x/tools/cmd/gorename
go get -u golang.org/x/tools/go/loader
go get -u golang.org/x/tools/go/buildutil
go get -u golang.org/x/tools/go/ast/astutil
go get -u github.com/kisielk/errcheck
go get -u github.com/zmb3/gogetdoc
  • 比较坑的是 gogetdoc因为只支持go1.6,我的是go1.5.1

vi ../zmb3/gogetdoc/ident.go +142编译不过,需要手动加函数修复...

  • 然后我试图呼唤'omnifunc' compelete,貌似还不成

原因受SirVer/ultisnips的快捷键冲突,我删除了SirVer/ultisnips

  • OK,这曲线救国啊 Bingo,一些自动补全的快捷键
Ctrl+P  向前切换成员
Ctrl+N  向后切换成员
Ctrl+E  表示退出下拉窗口, 并退回到原来录入的文字
Ctrl+Y  表示退出下拉窗口, 并接受当前选项
  • 其他补全
Ctrl+X Ctrl+L 整行补全
Ctrl+X Ctrl+N  根据当前文件里关键字补全
Ctrl+X Ctrl+K  根据字典补全
Ctrl+X Ctrl+T  根据同义词字典补全
Ctrl+X Ctrl+I  根据头文件内关键字补全
Ctrl+X Ctrl+]  根据标签补全
Ctrl+X Ctrl+F  补全文件名
Ctrl+X Ctrl+D  补全宏定义
Ctrl+X Ctrl+V  补全vim命令
Ctrl+X Ctrl+U  用户自定义补全方式
Ctrl+X Ctrl+S  拼写建议

四、我这时看到了补全里不用键入c-x,c-o就可以的neocomplete,于是安装,现在golang的补全看起来更自动化了。我喜欢neocomplete比ycm的安装简洁。

五、之后我想,既然研究了这么多,干脆把statusline也弄酷炫一点吧,于是安装了vim-airline。迁移替换了一些原有的statusline配置。

" for airline
"  let g:airline_section_a       (mode, crypt, paste, spell, iminsert)
"  let g:airline_section_b       (hunks, branch)
"  let g:airline_section_c       (bufferline or filename)
"  let g:airline_section_gutter  (readonly, csv)
"  let g:airline_section_x       (tagbar, filetype, virtualenv)
"  let g:airline_section_y       (fileencoding, fileformat)
"  let g:airline_section_z       (percentage, line number, column number)
"  let g:airline_section_error   (ycm_error_count, syntastic, eclim)
"  let g:airline_section_warning (ycm_warning_count, whitespace)
  function! AirlineInit()
    let g:airline_section_a = airline#section#create(['mode', ' ', 'branch'])
    let g:airline_section_b = airline#section#create_left(['hunks','file','%Y'])
    let g:airline_section_c = airline#section#create(['%F',' ','',' ','%B'])
    let g:airline_section_x = airline#section#create(['%{strftime("%c")}'])
  endfunction
  autocmd User AirlineAfterInit call AirlineInit()

  if !exists('g:airline_symbols')
    let g:airline_symbols = {}
  endif

  " unicode symbols
  let g:airline_left_sep = '»'
  let g:airline_left_sep = '▶'
  let g:airline_right_sep = '«'
  let g:airline_right_sep = '◀'
  let g:airline_symbols.crypt = '<U+1F512>'
  let g:airline_symbols.linenr = '␊'
  let g:airline_symbols.linenr = '␤'
  let g:airline_symbols.linenr = '¶'
  let g:airline_symbols.branch = '⎇'
  let g:airline_symbols.paste = 'ρ'
  let g:airline_symbols.paste = 'Þ'
  let g:airline_symbols.paste = '∥'
  let g:airline_symbols.spell = '<U+A7A8>'
  let g:airline_symbols.notexists = '∄'
  let g:airline_symbols.whitespace = 'Ξ'

六、neocomplete之外好像还有个neosnip没弄呢。

Plug 'Shougo/neocomplete'
Plug 'Shougo/neosnippet'
Plug 'Shougo/neosnippet-snippets'

这个neosnip可以指定自己个性化的snip所存在的位置,其他选项我不是很懂,大意就是快捷键<C-k>

let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
"  for neosnippet Plugin key-mappings.
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)
"  SuperTab like snippets behavior.
"  imap <expr><TAB>
"  \ pumvisible() ? "\<C-n>" :
"  \ neosnippet#expandable_or_jumpable() ?
"  \    "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
            \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
"  for conceal markers.
if has('conceal')
    set conceallevel=2 concealcursor=niv
endif

七、回想下,ipad上怎么才能很舒服的写golang呢?似乎问题没有解决耶。