Skip to content

Instantly share code, notes, and snippets.

@mccurdyc
Created August 30, 2019 14:05
Show Gist options
  • Save mccurdyc/01040be7d309134ad3a2ab7d32224034 to your computer and use it in GitHub Desktop.
Save mccurdyc/01040be7d309134ad3a2ab7d32224034 to your computer and use it in GitHub Desktop.
Golang NeoVim Autocomplete Config
call plug#begin('~/.vim/plugged')
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-gocode.vim'
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim
call plug#end()
" Plugin: 'prabirshrestha/asyncomplete.vim'
" Tab completion
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<cr>"
" refresh suggestions on backspace
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ asyncomplete#force_refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
set completeopt+=preview
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
" https://github.com/prabirshrestha/asyncomplete.vim#language-server-protocol-lsp
if executable('gopls')
" pip install python-language-server
au User lsp_setup call lsp#register_server({
\ 'name': 'gopls',
\ 'cmd': {server_info->['gopls']},
\ 'whitelist': ['go'],
\ })
endif
" https://github.com/prabirshrestha/asyncomplete-gocode.vim
call asyncomplete#register_source(asyncomplete#sources#gocode#get_source_options({
\ 'name': 'gocode',
\ 'whitelist': ['go'],
\ 'completor': function('asyncomplete#sources#gocode#completor'),
\ 'config': {
\ 'gocode_path': expand('~/go/bin/gocode')
\ },
\ }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment