doufang2228 2014-01-28 07:43
浏览 83

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

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 i.e. 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!

  • 写回答

1条回答 默认 最新

  • duankui6150 2014-01-28 08:06
    关注

    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, e.g. $GOROOT/misc/vim/update.sh or cd misc; vim/update.sh or 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!

    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码