LoginSignup
55
49

More than 1 year has passed since last update.

Vim で golang を書く環境を整える

Last updated at Posted at 2016-03-14

個人ブログに移動しました。


vimでgo言語のコーディングをする場合にsyntaxであったり、gofmt,goimportsを使って
コーディングを楽にできるのですが、色々書いてくれている人の記事が個人的に複雑に感じたので
個人的にまとめてみました。

golangのインストール

OS X

$ brew install golang

CentOS

$ sudo yum install golang --enablerepo=epel

Ubuntu

$ sudo apt install golang

GOPATH用のディレクトリを作成

$ mkdir $HOME/.golang
$ mkdir $HOME/go

.zshrc への環境変数の設定(bashの場合は.bashrc)

  • vim ~/.zshrc で編集
export GOPATH=$HOME/go
export GOROOT=$( go env GOROOT )
export PATH=$GOPATH/bin:$PATH
  • .zshrcの再読み込み(bashの場合は.bashrc)
$ source ~/.zshrc

vim-go のインストール

vim-goの前にvimのプラグイン管理をインストール

今回はvimのプラグイン管理としてvim-plugを使います。

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
 https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

.vimrcの編集

  • vim ~/.vimrc
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
call plug#end()

pluginのインストール

  • プラグインインストール
vim +PlugInstall +q +q
vim +GoInstallBinaries +q +q
  • goimports が実行されるよう設定を追加
$ vi ~/.vimrc
let g:go_fmt_command = "goimports"
55
49
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
55
49