LoginSignup
21
20

More than 5 years have passed since last update.

Go用のvim設定

Last updated at Posted at 2013-09-26

環境変数の設定

GOROOT環境変数

Getting Started - The Go Programming Languageによると、(バイナリパッケージで) /usr/local/go (WindowsではC:\Go)以外の場所にインストールした場合はGOROOT環境変数を設定する必要があるそうです。

私は/usr/local/goにインストールしています。

GOPATH環境変数

GOPATHはgo getでサードパーティのライブラリソースをインストールするディレクトリを設定します。私は~/goにしています。

export GOPATH=~/go

PATH環境変数

あとは~/.bash_profileに以下の行を追加してPATHを通しておきます。

export PATH=$PATH:/usr/local/go/bin

vim設定

jnwhiteh/vim-golangを参考にしています。

" go setttings
filetype off
filetype plugin indent off
set runtimepath+=/usr/local/go/misc/vim
au FileType go setlocal sw=4 ts=4 sts=4 noet
au FileType go setlocal makeprg=go\ build\ ./... errorformat=%f:%l:\ %m
au BufWritePre *.go Fmt
filetype plugin indent on
syntax on

Goにはgofmtというソースコード整形ツールがあります。au FileType go setlocal sw=4 ts=4 sts=4 noetはgofmtに合わせてタブでインデントするための設定です。

au FileType go setlocal makeprg=go\ build errorformat=%f:%l:\ %m:makeでビルドして:copenでビルドエラーのquickfixウィンドウを開くための設定です。

au BufWritePre *.go Fmtはファイル保存時にgofmtを実行するための設定です。

21
20
1

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
21
20