brew install go
創(chuàng)新互聯(lián)長(zhǎng)期為上1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為豐林企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)、做網(wǎng)站,豐林網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
輸入 brew info go 或者 go env 即可查看當(dāng)前安裝的golang版本信息
注意:千萬(wàn)不要把GOPATH設(shè)置成go的安裝路徑,可以自己在用戶目錄下創(chuàng)建一個(gè)目錄,例如mygo
一般安裝好go之后,使用go env查看一下當(dāng)前環(huán)境。此時(shí)顯示出來(lái)的GOROOT就是你使用brew安裝go的安裝目錄,這個(gè)路徑要記下來(lái)。接下來(lái)要在bash_profile文件中進(jìn)行配置。
使用vim ~/.bash_profile
然后在這個(gè)文件中進(jìn)行編輯,下面以我的電腦為例,路徑這種要根據(jù)不同人的情況而定
GOROOT=/usr/local/Cellar/go/1.10.1/libexec (改成自己的go安裝目錄 go env命令可查看)
export GOROOT (不用動(dòng))
export GOPATH=/Users/jiangqiaowei/mygo (創(chuàng)建一個(gè)自己的文件夾 管理go相關(guān)內(nèi)容)
export GOBIN=$GOPATH/bin (不用改)
export PATH=$PATH:$GOBIN:$GOROOT/bin (不用改)
$ go get golang.org/x/mobile/cmd/gomobile (需要墻)
gomobile init
$ go get -d golang.org/x/mobile/example/bind/...
$ cd $GOPATH/src/golang.org/x/mobile/example/bind
$ gomobile bind -target=ios golang.org/x/mobile/example/bind/hello
此命令在ios/路徑下生成bind.xcodeprojxcode項(xiàng)目以及 在bind/目錄下生成一個(gè) hello.framework
拖入項(xiàng)目即可使用
1、編譯vimgdb
下載vimgdb73和vim73
mkdir -p ./tmp
cd tmp
tar zxvf ../vim-7.3.tar.gz
unzip ../vimgdb-for-vim7.3-master.zip
mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3
patch -p0 vimgdb-for-vim7.3/vim73.patch
cd vim73
安裝依賴
sudo apt-get install build-essential
sudo apt-get build-dep vim-gtk
sudo apt-get install libncurses5-dev
安裝
// 這里直接執(zhí)行make的操作
make
sudo make install
安裝vimgdb runtime
cd ../vimgdb-for-vim7.3
cp vimgdb_runtime ~/.vim/bundle
打開(kāi)vim
:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件
添加配置.vimrc
" vimgdb插件
run macros/gdb_mappings.vim
在vim中執(zhí)行g(shù)db時(shí),報(bào) “Unable to read from GDB pseudo tty” 的錯(cuò)誤,因?yàn)闆](méi)有安裝 gdb ,所以安裝gdb
sudo apt-get install gdb
2、安裝vundle
set up vundle
$ git clone ~/.vim/bundle/vundle
Configure Plugins
在.vimrc文件的開(kāi)頭添加下面的內(nèi)容,有些不是必須的,可以注掉
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin ''
" ...
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" : PluginList - list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
3、官方vim-lang插件
Config vim file .vimrc,Add content bellow in bottom of the file
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
" reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre Fmt
4、代碼補(bǔ)全的插件gocode
配置go的環(huán)境變量,比如我的配置,GOPATH變量是必須要配置的,PATH中必須把GOPATH的bin也添加進(jìn)去,否則沒(méi)有自動(dòng)提示,會(huì)提示找不到模式
export GOROOT=/usr/local/go
export GOPATH=/data/app/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Set up gocode
Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:
go get -u github.com/nsf/gocode (-u flag for "update")
Configure vim in .vimrc file
Plugin 'nsf/gocode', {'rtp': 'vim/'}
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
寫(xiě)一個(gè)helloword程序,輸入fmt后按C-xC-o如果能看到函數(shù)的聲明展示出來(lái),說(shuō)明安裝是正確的。
4、代碼跳轉(zhuǎn)提示godef
Set up godef
go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
git clone ~/.vim/bundle/vim-godef
Configure vim in .vimrc file
Bundle 'dgryski/vim-godef'
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
5、代碼結(jié)構(gòu)提示gotags
Set up gotags
go get -u github.com/jstemmer/gotags
Put the following configuration in your vimrc:
Bundle 'majutsushi/tagbar'
nmap :TagbarToggle
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
命令模式下按在右邊就會(huì)顯示當(dāng)前文件下的函數(shù)名,結(jié)構(gòu)體名等等,光標(biāo)放到相應(yīng)的tag上,按回車可以快速跳到程序中的相應(yīng)位置。
再次按會(huì)關(guān)閉tag窗口。
PS:本地的.vimrc的配置
" 插件管理器 vundle
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
" Plugin 'tpope/vim-fugitive'
" Plugin 'Lokaltog/vim-easymotion'
" Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
" Plugin 'L9'
" Plugin 'FuzzyFinder'
" scripts not on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin ''
" ...
"
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
" filetype plugin on
"
" Brief help
" : PluginList - list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
syntax on
" ********************************************************************
" 這里省略了其它不相關(guān)的插件
" vimgdb插件
run macros/gdb_mappings.vim
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
" reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre buffer Fmt
" 代碼補(bǔ)全的插件
Bundle 'Blackrush/vim-gocode'
" 代碼跳轉(zhuǎn)提示
Bundle 'dgryski/vim-godef'
" 代碼結(jié)構(gòu)提示
Bundle 'majutsushi/tagbar'
nmap F8 :TagbarToggleCR
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
第一種:LiteIDE
LiteIDE是一個(gè)簡(jiǎn)單的開(kāi)源IDE,值得注意的是,它是GO語(yǔ)言2012年正式版發(fā)布的首個(gè)IDE,由Qt開(kāi)發(fā),它看起來(lái)類似于Visual Studio等其他編譯器。
由于它是為golang設(shè)計(jì)的,LiteIDE為開(kāi)發(fā)人員提供了許多有用的功能,包括可配置的構(gòu)建命令,高級(jí)代碼編輯器和廣泛的golang支持。其他功能包括代碼管理、gdb、Delve調(diào)試器、自動(dòng)完成和使用WordApi的主題,基于MIME類型的系統(tǒng)等。
第二種:VS Code
它是微軟開(kāi)發(fā)的廣受歡迎的開(kāi)源IDE,有一個(gè)開(kāi)箱即用的go擴(kuò)展可供VS Code使用。VS Code插件為開(kāi)發(fā)人員提供了很多功能,包括與許多go工具集成。
VS Code通過(guò)IntelliSense,內(nèi)置git集成,直接從編譯器調(diào)試代碼等功能提供智能完成功能;VS Code具有高度可擴(kuò)展性,并通過(guò)其許多擴(kuò)展提供了許多自定義選項(xiàng),還提供了幾十種語(yǔ)言的支持,成為受開(kāi)發(fā)者歡迎的工具。
第三種:Atom
開(kāi)發(fā)人員可以利用這個(gè)Atom IDE改進(jìn)的語(yǔ)言集成與更智能的編輯器。開(kāi)源的go-plus軟件包使開(kāi)發(fā)人員更容易在GO中進(jìn)行編程。
Atom和go-plus軟件包為golang提供工具,構(gòu)建流程,linters、vet和coverage工具的支持;其他功能包括自動(dòng)完成、格式化、測(cè)試和文檔。
第四種:Vim
Vim有許多插件可以幫助開(kāi)發(fā)人員更輕松地編輯他們的GO代碼;Vim-go插件自動(dòng)安裝所有必要的東西,為Vim中的GO開(kāi)發(fā)人員提供更平滑的集成。
Vim-go具有許多有用的功能,包括編譯器,改進(jìn)的語(yǔ)法高亮和折疊,完成支持以及一系列具有集成支持的調(diào)試程序。還有一些使用的高級(jí)源分析工具,包括GoImplements、GoCallees和GoReferrers。
網(wǎng)頁(yè)標(biāo)題:go語(yǔ)言vim go語(yǔ)言viper
文章源于:http://jinyejixie.com/article44/doscehe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、定制開(kāi)發(fā)、網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)