LoginSignup
75
73

More than 5 years have passed since last update.

Goをインストールし、Vimで書く環境を整えるまでの手順

Last updated at Posted at 2014-06-07

概要

Go言語をインストールして実行できる環境を作る。
VimでGo言語を書く設定をする。

Goのインストール

以下のページでバイナリをダウンロードし、ホームディレクトリに設置する。
https://code.google.com/p/go/wiki/Downloads?tm=2

$ wget https://storage.googleapis.com/golang/go1.2.2.linux-amd64.tar.gz
$ tar xvzf go1.2.2.linux-amd64.tar.gz
$ mv go1.2.2.linux-amd64 ~/go

Goのパッケージをダウンロードして設定するディレクトリを作成する。

$ mkdir ~/go/packages

.bashrcなどに、以下の環境変数を設定する。

export GOROOT=~/go
export GOPATH=$GOROOT/packages
export PATH=$PATH:$GOROOT/bin

「. ~/.bashrc」などで設定を有効化すると、goコマンドが使用できるようになる。

Vimの設定

入力補完のために、gocodeを入れる。

$ go get github.com/nsf/gocode

Goに同封されているVimの設定とgocodeのVimの設定を読み込むために、
.vimrcに以下の設定を追記する。

.vimrc
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre <buffer> Fmt
exe "set rtp+=".globpath($GOPATH, "src/github.com/nsf/gocode/vim")
set completeopt=menu,preview

これで自動補完や自動フォーマットが動作するようになる。

「:Import fmt」で、importを追加できたりするのも便利。

参考

Vimを使ったGo言語開発手法
http://mattn.kaoriya.net/software/vim/20130531000559.htm

Go言語のインストール
http://golang.jp/install

GOPATH は適当に決めて問題ない
http://qiita.com/yuku_t/items/c7ab1b1519825cc2c06f

Go言語の開発環境構築 (Golang + Mac OS X + Vim)
http://note-of-engineer-b.blogspot.jp/2013/12/golang-setup.html

75
73
0

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
75
73