Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim as Golang IDE #5

Open
rainyear opened this issue Mar 28, 2015 · 1 comment
Open

Vim as Golang IDE #5

rainyear opened this issue Mar 28, 2015 · 1 comment
Assignees

Comments

@rainyear
Copy link
Owner

主要记录、备份Vim的个性化配置跟Go开发环境的搭建,大部分是从OS X 10.10 已有的配置迁移到 Debian (32bit)上。

0. 效果:

vim-go

1. 安装 Vim 7.4 with Lua support

用到的Vim补全插件要求 Lua 支持,至少需要Vim7.4以上版本。

# 卸载系统原有的 vim 组件
sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common
sudo rm -rf /usr/local/share/vim
sudo rm /usr/bin/vim

# 安装必要库(lua版本可选)
apt-get install python-dev lua5.2 liblua5.2 make libperl-dev libc6-dev

# 调整 Lua 相关 lib,适配Vim的配置安装(**最易出问题的一步**)
sudo mkdir /usr/include/lua5.2/include
sudo cp /usr/include/lua5.2/*.h /usr/include/lua5.2/include/ 

find / -name liblua5.2.so
sudo ln -s /usr/lib/i386-linux-gnu/liblua5.2.so /usr/local/lib/liblua.so

sudo ln -s /usr/local/bin/luajit /usr/bin/luajit

下载并解压 Vim74 源码,进入vim74/src

./configure --with-features=huge \
            --enable-largefile \
            --enable-cscope \
            --enable-pythoninterp \
            --enable-perlinterp \
            --enable-luainterp \
            --with-luajit \
            --with-lua-prefix=/usr/include/lua5.2 \
            --enable-fail-if-missing

# 如果有不满足的条件会失败中断(--enable-fail-if-missing),若没问题继续
make 
sudo make install

# 检验是否安装成功
vim --version | grep 'lua'
# + lua 表示成功,- lua 表示没有成功加入 lua support
#
vim
:echo has("lua")
#1 or 0

2. install Golang

参考:Official Docs

# 下载适合版本的安装包
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

# 设置 GOROOT & GOPATH
export GOPATH=/path/to/your/gocode
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH

3. Vim 配置与插件

参考:~/.vimrc

插件管理使用Vundle

.vimrc 写好之后,打开 vim,执行::PluginInstall,自动下载相关插件,其中vim-go需要 godoc 等支持,在 vim 中执行:GoInstallBinaries,会自动下载所需工具到 GOPATH 中。

最后用 vim 编辑 .go 文件,就可以得到最开始的效果图的样子,不过要注意如果只是想执行单个 go 文件,映射的快捷键是<,+b>,如果是加载 GOPATH 中的包执行,映射的是<,+r>


Update 2015.4.8

goimports 安装失败的问题,go get golang.org/x/tools/cmd/goimports,官网已经被move掉了…可以去github.com/golang/tools获取源码,将目录改为golang.org/x/tools/,然后执行go install,就可以在$GOPATH/bin看到可执行文件,然后更新Vim配置,加上let g:go_fmt_command = "goimports",就可以实现auto import了。

参考

  1. Installing vim 7.4 with lua on Ubuntu 12.04
  2. Setting up Vim as your Go IDE
@rainyear rainyear added the Note label Mar 28, 2015
@rainyear rainyear self-assigned this Mar 28, 2015
@anbylau2130
Copy link

mark

This was referenced Sep 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants