
正文
go语言安装包vim包 golang安装包
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何配置go语言集成开发环境 vim
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
安装
// 这里直接执行make的操作
make
sudo make install
安装vimgdb runtime
cd ../vimgdb-for-vim7.3
cp vimgdb_runtime ~/.vim/bundle
打开vim
:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件
添加配置.vimrc
" vimgdb插件
run macros/gdb_mappings.vim
在vim中执行gdb时,报 “Unable to read from GDB pseudo tty” 的错误,因为没有安装 gdb ,所以安装gdb
sudo apt-get install gdb
2、安装vundle
set up vundle
$ git clone ~/.vim/bundle/vundle
Configure Plugins
在.vimrc文件的开头添加下面的内容,有些不是必须的,可以注掉
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、代码补全的插件gocode
配置go的环境变量,比如我的配置,GOPATH变量是必须要配置的,PATH中必须把GOPATH的bin也添加进去,否则没有自动提示,会提示找不到模式
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
写一个helloword程序,输入fmt后按C-xC-o如果能看到函数的声明展示出来,说明安装是正确的。
4、代码跳转提示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、代码结构提示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'
\ }
命令模式下按在右边就会显示当前文件下的函数名,结构体名等等,光标放到相应的tag上,按回车可以快速跳到程序中的相应位置。
再次按会关闭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
" ********************************************************************
" 这里省略了其它不相关的插件
" 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
" 代码补全的插件
Bundle 'Blackrush/vim-gocode'
" 代码跳转提示
Bundle 'dgryski/vim-godef'
" 代码结构提示
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'
\ }
相关问答
Q1: 如何在Windows下安装Go语言编程环境
下载安装包
安装包下载地址:golang.org/dl/
这里选择下载Windows版本,点击链接打开go语言安装包vim包的页面可能不会开始下载go语言安装包vim包;地址栏里会显示完整go语言安装包vim包的下载地址,如:golang.org/doc/install?download=go1.5.1.windows-amd64.msi,不开始下载也没关系,我们复制一下下载地址,用迅雷之类的下载工具下。
开始安装
一路下一步就行了,没什么需要设置的,安装目录最好保持默认,避免遇到一些怪问题。
安装完成之后就可以打开命令行,看看安装成功了没有;
任意目录下,直接执行“go”,能看到类似以下内容就对了:
或者执行:
[plain] view plain copy
C:\go version
go version go1.5.1 windows/amd64
注意:我在安装完成之后执行“go”的时候就提示找不到文件或目录,我打开环境变量,在用户变量里加了一个PATH,
检查系统变量“PATH”中也有“C:\Go\bin”,然后就在后面加了一个分号,确定保存之后再打开命令行就可以了,也不知道到底是哪个起作用了。
Q2: 4.1 Go语言中包(Packages)基础知识
先看一下目录结构,注意这里的src名称是必须的,go在设置了GOPATH后,默认会添加src去寻找package,暂未查询是否有方法不按照src查询
根据上面的描述,Go语言中通过包中函数的名称来区分公共函数和私有函数,我们在main函数中是无法调用myPrivateFunc的
此时如果执行通过go run方式执行,会看到如下的提示信息,这与大部分语言对于包管理方式相关,所以我们通过两种不同的方法来让代码执行起来
返回如下,这里面对我们后续执行有影响的两个参数GO111MODULE和GOPATH
如果要使用gopath模式引用包,则需要关闭mod模式
设置GOPATH为当前路径,即main.go所在的路径
此时再查看go env时,GOPATH已经发生改变
我们再次尝试执行代码
可以看到public函数被调用
Q3: phpstorm golang开发环境如何配置
golang 有编辑器可以用 如国人开发的liteide,或者sublimetext、vim、emacs,为什么一定要用phpstorm?如果你只是做php开发,phpstorm很不错,如果用golang来开发,phpstorm 并不合适
Q4: 如何安装Go语言安装包
go语言作为google的一个主推语言,最近很多人都在研究,也花了一点时间对他的安装进行了测试,本人使用Sublime Text 2 + GoSublime + gocode
顾名思义首先是安装Go,这里有很详细的安装说明, 或者(golang.org自己去找hosts),官方已经支持Windows版本
下载解压配置环境变量
“环境变量”(我的电脑-高级系统设置-环境变量),在系统变量的标签下,依次新建编辑如下几个键值对:
(1). 新建 变量名:GOBIN 变量值 :c:\go\bin
(2). 新建 变量名:GOARCH 变量值:386
(3). 新建 变量名:GOOS 变量值:windows
(4). 新建 变量名: GOROOT 变量值:c:\go
(5). 编辑 Path 在Path的变量值的最后加上 %GOBIN%
1. 下载 Sublime Text 2,地址如下:
2. 解压以后,双击 sublime_text,就可以使用 Sublime Text 2 了。
破解:
用 WinHex 编辑 sublime_text_backup.exe 文件, 跳到 000CBB70 那一行,将该行的 8A C3 修改为 B0 01 然后保存
破解注册成功
3. 安装 Package Control,在打开 Sublime Text 2以后,按下快捷键 Ctrl + `,打开命令窗行(具体在view——show Console),并回车:
import urllib2,os; pf=’Package Control.sublime-package’; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),’wb’).write(urllib2.urlopen(‘’+pf.replace(‘ ‘,’%20′)).read()); print ‘Please restart Sublime Text to finish installation’
4. 重启Sublime Text 2后,就可以发现在 Preferences菜单下,多出一个菜单项 Package Control。
5.现在安装GoSublime插件了,按住Ctrl+Shilft+p会弹出一个对话框输入install回车弹出一个安装包的对话框
同上输入GoSublime选择GoSublime回车
本机已经安装所以没有出现选项,输入Go build选中回车(这个属于可选)
到此GoSublime安装成功
6.下面安装gocode,
首安装 Git-1.7.11-preview20120710。
打开控制台,输入以下内容:
go get github.com/nsf/gocode
go install github.com/nsf/gocode
go get github.com/DisposaBoy/MarGo
go install github.com/DisposaBoy/MarGo
也可以去github下载(要安装google的git版本管理工具)
安装完成后,我们可以在 go/bin 目录下,发现多出了个 gocode 文件。(一定要放在bin目录下)
7. 修改GoSublime配置:在 Preferences菜单下,找到Package Settings,然后找到 GoSublime,再往下找到 Settings – Default。再打开的文件中,添加如下配置,并保存:
"env": {"path":"c:/go/bin;" },
好了,到目前为止,开发环境搭建完成。
下面可以自由编程了。呵呵。
按下快捷键 Ctrl + b 界面下方会出现如下界面:
好了,到现在,开发环境就搭建完毕了。
如下是内容我这边没有使用照样可以使用:
sublime Text 2 编译配置设置方法
tools-build system-new build system 新建一个配置文件 设置为
{
“cmd”: ["go", "run", "$file_name"],
“file_regex”: “^[ ]*File \”(…*?)\”, line ([0-9]*)”,
“working_dir”: “$file_path”,
“selector”: “source.go”
}
然后就可以用ctrl+b 编译了
保存
关于go语言安装包vim包和golang安装包的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







