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.

Related to my original question, I think I know I can just go to:

https://github.com/nsf/gocode

copy the files that they provide there and just start using the vim autocomplete. However, I wanted to know what people thought and how the go community has the vim autocomplete set up.

Also, I have followed the intructions as were posted there and I still cannot make the autocompletion work for my go in 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.

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:

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.

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. Is that everything I have to do for that step?

On step 2 it says:

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:

#!/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? 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?

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. 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?

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. I have other stuff that seems irrelevent like an fmt.vim import.vim and a test.sh file.

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. 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. Feel free to share that too!


Have you executed the update.sh command already? 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). To backup your Vim configuration, just store those somewhere (or put all of your dotfiles under version control, as many now do).

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 / ). With this, you can invoke the script from anywhere, eg $GOROOT/misc/vim/update.sh or cd misc; vim/update.sh cd misc; vim/update.sh or 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. Just give it a try!

链接地址: http://www.djcxy.com/p/18790.html

上一篇: 如何修复/隔离硬盘坏块

下一篇: 为Go编程语言设置vim自动完成功能