LoginSignup
43
41

More than 5 years have passed since last update.

Go言語で開発を始める前のvimの設定

Last updated at Posted at 2014-07-31

goのインストールからvim周りの環境設定の方法まとめ。

goのインストール

$ brew install go hg

環境変数の設定

export GOPATH=$HOME/.go
#export GOROOT=`go env GOROOT`
export PATH=$GOPATH/bin:$PATH

gocodeのインストール

入力補完のためにgocodeをインストール

$ go get github.com/nsf/gocode

vimの設定

vimを使ってgo言語で開発するときに設定

ランタイムパスの設定

set rtp+=$GOROOT/misc/vim

入力補完を行う

$GOPATHを設定

exe "set rtp+=".globpath($GOPATH, "src/github.com/nsf/gocode/vim”)

vim-go のインストール

NeoBundle 使う場合

NeoBundle 'fatih/vim-go'

使い方

  • :GoImport <package_name> ファイルにインポート設定追加
  • :GoBuild ファイルビルド
  • :GoRun スクリプト即時実行

詳しくはgithubに。 https://github.com/fatih/vim-go

.vimrcの設定の例

let g:go_bin_path = expand("~/.go/bin")

exe "set rtp+=".globpath($GOPATH, "src/github.com/nsf/gocode/vim")
set completeopt=menu,preview
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)

参考

43
41
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
43
41