简体   繁体   中英

vim-go autocompletion not working

I recently installed vim-go using pathogen, but the autocompletion feature is not working. If I am using it only shows commands I've already used. My .vimrc has

filetype plugin on

" Enable autocompletion
set omnifunc=syntaxcomplete#Complete
" Select keyword as you type
:set completeopt=longest,menuone

Do I need more than just this plugin? The other feature I have tested so far are working (:GoRun, syntax highlighting). This is on a Ubuntu machine.

Are you typing CX CO to open the autocompletation window? This works fine for me.

On the other hand, if you want to get real-time completion (completion by type) install the following plugins YCM or neocomplete

The syntaxcomplete#Complete ships with Vim, not the Go filetype plugin, and it has very limited capabilities (basically, just offering the language's keywords). No wonder you're disappointed.

The ftplugin/go.vim file sets the correct, custom completion of the vim-go plugin:

setlocal omnifunc=go#complete#Complete

So, just ensure that the 'filetype' setting is correct ( go ), and that you don't have any additional configuration that overrides the plugin's.

:verbose setlocal omnifunc?

can tell you.

If none of these suggestions solves your problem, try killing gocode from a terminal:

gocode exit (or killall gocode it that fails)
gocode -s -debug

In case of startup failure due to a lingering unix socket, simply remove it and try again. Once everything is working, you can terminate the debug enabled gocode process (the plugin will autostart as needed)

This is what worked for me. default gocode pkg seems to be no longer maitained. so update it with the one below. my go and vim versions:

VIM - Vi IMproved 8.2
go version go1.16.4 

follow the steps below:

gocode exit 
go get -u github.com/mdempsky/gocode

run gocode in debug mode

gocode -s -debug

try the autocomplete.(vim-go C+X C+O)

viola! you should see the list like so:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM