英文:
Go: vim autocomplete <ENTER> command don't works
问题
在我按下回车键并光标移到下一行时,Vim中的自动补全功能不起作用。
这是我的.vimrc配置:https://github.com/marcosvidolin/dotfiles/blob/master/.vimrc
弹出窗口示例:
谢谢
英文:
autocomplete in vim doesn't work when I hit ENTER and the cursor go to the next line.
this is my .vimrc configuration: https://github.com/marcosvidolin/dotfiles/blob/master/.vimrc
Popup example:
Thanks
答案1
得分: 2
你需要将以下内容添加到你的 .vimrc 文件中:
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>"
英文:
you need to add this to your .vimrc
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>"
source : Completion with sources
答案2
得分: 1
我正在使用vim,并使用Coc模块进行语言服务器配置。
尝试按照以下步骤进行操作:
- 安装gopls:
GO111MODULE=on go get golang.org/x/tools/gopls@latest
- 打开vim并输入
:CocConfig
,然后设置go语言的配置,如下所示(注意:可以根据需要自定义值,特别是在rootPatterns字段中)。
{
"languageserver": {
"golang": {
"command": "gopls",
"rootPatterns": ["go.mod", "main.go", ".vim/", ".git/", ".hg/"],
"filetypes": ["go"],
"initializationOptions": {
"usePlaceholders": true
}
}
}
}
- 保存文件并重新加载vim配置
英文:
I am using vim and using Coc module for language server configuration.
Try to run these following steps:
- Install gopls
GO111MODULE=on go get golang.org/x/tools/gopls@latest
- Open you vim and type
:CocConfig
and setting up go language configuration like the following bellow. (note: feel free to customize the value, especially in field rootPatterns)
{
"languageserver": {
"golang": {
"command": "gopls",
"rootPatterns": ["go.mod", "main.go", ".vim/", ".git/", ".hg/"],
"filetypes": ["go"],
"initializationOptions": {
"usePlaceholders": true
}
}
}
}
- Save File and Reload your vim configuration
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论