Go:vim自动完成<ENTER>命令无法正常工作

huangapple go评论120阅读模式
英文:

Go: vim autocomplete <ENTER> command don't works

问题

在我按下回车键并光标移到下一行时,Vim中的自动补全功能不起作用。

这是我的.vimrc配置:https://github.com/marcosvidolin/dotfiles/blob/master/.vimrc

弹出窗口示例:

Go:vim自动完成<ENTER>命令无法正常工作

谢谢

英文:

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:

Go:vim自动完成<ENTER>命令无法正常工作

Thanks

答案1

得分: 2

你需要将以下内容添加到你的 .vimrc 文件中:

  1. inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>"

来源:Completion with sources

英文:

you need to add this to your .vimrc

  1. inoremap &lt;silent&gt;&lt;expr&gt; &lt;cr&gt; coc#pum#visible() ? coc#_select_confirm() : &quot;\&lt;C-g&gt;u\&lt;CR&gt;&quot;

source : Completion with sources

答案2

得分: 1

我正在使用vim,并使用Coc模块进行语言服务器配置。
尝试按照以下步骤进行操作:

  • 安装gopls:GO111MODULE=on go get golang.org/x/tools/gopls@latest
  • 打开vim并输入:CocConfig,然后设置go语言的配置,如下所示(注意:可以根据需要自定义值,特别是在rootPatterns字段中)。
  1. {
  2. "languageserver": {
  3. "golang": {
  4. "command": "gopls",
  5. "rootPatterns": ["go.mod", "main.go", ".vim/", ".git/", ".hg/"],
  6. "filetypes": ["go"],
  7. "initializationOptions": {
  8. "usePlaceholders": true
  9. }
  10. }
  11. }
  12. }
  • 保存文件并重新加载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)
  1. {
  2. &quot;languageserver&quot;: {
  3. &quot;golang&quot;: {
  4. &quot;command&quot;: &quot;gopls&quot;,
  5. &quot;rootPatterns&quot;: [&quot;go.mod&quot;, &quot;main.go&quot;, &quot;.vim/&quot;, &quot;.git/&quot;, &quot;.hg/&quot;],
  6. &quot;filetypes&quot;: [&quot;go&quot;],
  7. &quot;initializationOptions&quot;: {
  8. &quot;usePlaceholders&quot;: true
  9. }
  10. }
  11. }
  12. }
  • Save File and Reload your vim configuration

huangapple
  • 本文由 发表于 2022年8月20日 23:37:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/73427981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定