简体   繁体   English

为Go编程语言设置vim自动完成功能

[英]Setting up vim autocomplete for the Go programming language

EDIT: 编辑:

I was generally interested to know how people had their go autocomplete set up for vim and was looking for advice on it. 我通常很想知道人们是如何为vim设置自动完成功能的,并正在寻求建议。

Related to my original question, I think I know I can just go to: 关于我最初的问题,我想我可以去:

https://github.com/nsf/gocode https://github.com/nsf/gocode

copy the files that they provide there and just start using the vim autocomplete. 复制它们提供的文件,然后开始使用vim自动完成功能。 However, I wanted to know what people thought and how the go community has the vim autocomplete set up. 但是,我想知道人们的想法以及go社区如何设置vim自动完成功能。

Also, I have followed the intructions as were posted there and I still cannot make the autocompletion work for my go in vim. 另外,我已经按照此处发布的指示进行操作,但是我仍然无法使自动完成功能在vim中发挥作用。 So I am looking for other alternatives or ideas on how to make it work. 因此,我正在寻找其他替代方案或想法,以使其发挥作用。 Not sure what the problem is. 不确定是什么问题。 Currently when I try to autocomplete it simply writes the word PANIC instead of showing me the options for autocompletion. 当前,当我尝试自动完成时,它只写了PANIC一词,而不是向我显示自动完成的选项。

ORIGINAL: 原版的:

I was trying to set up my vim such that it could auto complete the Go programming language, however, I was following the instructions in the following page: 我试图设置vim以使其能够自动完成Go编程语言,但是,我遵循以下页面中的说明:

https://github.com/nsf/gocode https://github.com/nsf/gocode

and I was not sure what they meant and I was a little scared of maybe changing my vim set up in a way that might be damaging by doing it wrongly. 我不确定它们是什么意思,我有点害怕改变我的vim设置,而这可能会因错误地执行而损坏。

The first thing that confused me is it says: 让我感到困惑的第一件事是:

Install official Go vim scripts from $GOROOT/misc/vim. If you did that already, proceed to the step 2.

However, I was not sure what that even meant. 但是,我不确定这意味着什么。 I did go to that directory in my terminal and read the readme.txt file and I it said how to activate the syntax highlighting which I already had anyway. 我确实进入了终端的那个目录并阅读了readme.txt文件,它说了如何激活我已经拥有的语法突出显示。 Is that everything I have to do for that step? 这就是我要做的一切吗?

On step 2 it says: 在第2步中说:

do: 做:

vim/update.sh

They actually provide the code that update.sh is but I was not sure what the beginning of the cp command meant ie its: 他们实际上提供了update.sh的代码,但是我不确定cp命令的开头是什么意思,即:

#!/bin/sh
mkdir -p "$HOME/.vim/autoload"
mkdir -p "$HOME/.vim/ftplugin/go"
cp "${0%/*}/autoload/gocomplete.vim" "$HOME/.vim/autoload"
cp "${0%/*}/ftplugin/go/gocomplete.vim" "$HOME/.vim/ftplugin/go"

But what does the ${0%/*} part do? 但是$ {0%/ *}部分有什么作用? and even if I know what the update.sh is, where do I even run this, since this vim/update.sh is done at a relative path? 即使我知道update.sh是什么,由于vim / update.sh是在相对路径上完成的,所以我什至在哪里运行它?

I know update.sh wants me to copy some files to $HOME/.vim/ftplugin/go and $HOME/.vim/autoload, but I even did a find from ~ and couldn't find such files, so I am unsure on what to copy. 我知道update.sh要我将一些文件复制到$ HOME / .vim / ftplugin / go和$ HOME / .vim / autoload,但是我什至从〜进行了查找,但是找不到此类文件,所以我不确定关于要复制的内容。 I know where it should go, but not where the file even is. 我知道应该去哪里,但文件不知道在哪里。 Does someone know where those files are or an easier or more detailed explanation on how to make vim auto-complete for go? 有人知道这些文件在哪里,或者更简单或更详细的说明如何使vim自动完成吗?

Thanks for the help in advance! 我在这里先向您的帮助表示感谢! :) :)


Some of the problems that I have discovered that I have, not sure if its expected, but in the $GOROOt/misc/vim/ftplugin/go I do not have the gocomplete.vim file at all. 我发现了一些问题,不确定是否可以预期,但是在$ GOROOt / misc / vim / ftplugin / go中,我根本没有gocomplete.vim文件。 I have other stuff that seems irrelevent like an fmt.vim import.vim and a test.sh file. 我还有其他似乎不相关的东西,例如fmt.vim import.vim和test.sh文件。

But the odd thing is that at $GOROOt/misc/autoload I do not have the gocomplete.vim file but I instead have a complete.vim file. 但是奇怪的是,在$ GOROOt / misc / autoload中,我没有gocomplete.vim文件,但是我有一个complete.vim文件。 Not sure if that the same or why the name of the file would have changed. 不确定是否相同或为什么文件名会更改。 Anyway has their go autocomplete set up and mind sharing what they have and if they know what the differences might be with what I have encountered? 无论如何,他们都设置了自动完成功能,并与他人共享他们所拥有的东西,如果他们知道与我所遇到的东西可能会有什么不同? Thanks! 谢谢!


ADDITION to Question 除问题外

I am also generally interested in how other people have their auto-complete set up for their go in vim. 我通常也对其他人如何在Vim中设置自动完成功能感兴趣。 Feel free to share that too! 也可以随意分享!

Have you executed the update.sh command already? 您是否已经执行过update.sh命令? I'm pretty confident that it will work. 我非常有信心它将起作用。

All of your Vim configuration is stored in ~/.vim/ , ~/.vimrc and ~/.gvimrc (with Vim 7.4, you can put the last two also inside the first directory). 您所有的Vim配置都存储在~/.vim/~/.vimrc~/.gvimrc (对于Vim 7.4,您也可以将最后两个放在第一个目录中)。 To backup your Vim configuration, just store those somewhere (or put all of your dotfiles under version control, as many now do). 要备份您的Vim配置,只需将其存储在某个位置(或像现在许多一样,将所有dotfile置于版本控制下)。

The ${0%/*} manipulates the script's file name ( $0 ) like dirname does: It cuts off the script file name itself (everything at the end * until the last / ). ${0%/*}dirname一样操作脚本的文件名( $0 ):切断脚本文件名本身(末尾*直到最后一个/ )。 With this, you can invoke the script from anywhere, eg $GOROOT/misc/vim/update.sh or cd misc; vim/update.sh 这样,您可以从任何地方调用脚本,例如$GOROOT/misc/vim/update.shcd misc; vim/update.sh cd misc; vim/update.sh or cd misc/vim; ./update.sh cd misc; vim/update.shcd misc/vim; ./update.sh cd misc/vim; ./update.sh . cd misc/vim; ./update.sh

The script also ensures that the autoload and ftplugin subdirs exist, and creates them if they don't yet. 该脚本还确保autoloadftplugin子目录存在,并创建子目录(如果尚不存在)。 Just give it a try! 试一试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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