英文:
vim-go autocompletion not working
问题
我最近使用 pathogen 安装了 vim-go,但自动补全功能不起作用。如果我使用<C-x><C-o>,它只会显示我已经使用过的命令。
我的 .vimrc 文件中有以下内容:
filetype plugin on
" 启用自动补全
set omnifunc=syntaxcomplete#Complete
" 输入关键字时进行选择
:set completeopt=longest,menuone
除了这个插件,我还需要其他的东西吗?我已经测试过其他功能了(:GoRun,语法高亮)。
这是在 Ubuntu 机器上的情况。
英文:
I recently installed vim-go using pathogen, but the autocompletion feature is not working. If I am using <C-x><C-o> 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.
答案1
得分: 8
你是否在使用C-X C-O来打开自动补全窗口?这对我来说很有效。
另外,如果你想要实时补全(按类型进行补全),请安装以下插件YCM
或neocomplete
。
英文:
Are you typing C-X C-O 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
答案2
得分: 7
syntaxcomplete#Complete
是Vim自带的功能,而不是Go文件类型插件,并且它的功能非常有限(基本上只提供语言的关键字)。难怪你感到失望。
ftplugin/go.vim
文件设置了vim-go插件的正确自定义完成方式:
setlocal omnifunc=go#complete#Complete
所以,请确保'filetype'
设置正确(为go
),并且没有其他配置覆盖了插件的设置。
可以使用命令:verbose setlocal omnifunc?
来查看。
英文:
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.
答案3
得分: 0
如果这些建议都不能解决你的问题,尝试从终端关闭 gocode:
gocode exit(如果失败,尝试 killall gocode)
gocode -s -debug
如果由于残留的 Unix 套接字导致启动失败,只需删除它并重试。一旦一切正常工作,你可以终止启用调试模式的 gocode 进程(插件将根据需要自动启动)。
英文:
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)
答案4
得分: 0
这是对我有效的方法。默认的gocode包似乎不再维护了,所以用下面的方法更新它。
我的go和vim版本:
VIM - Vi IMproved 8.2
go version go1.16.4
按照以下步骤进行操作:
gocode exit
go get -u github.com/mdempsky/gocode
以调试模式运行gocode
gocode -s -debug
尝试自动完成(vim-go C+X C+O)
完成!你应该会看到如下列表:
英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论