
正文
ctags支持go语言 go语言插件
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
linux+ctag是什么 相关百度经验 组图
Linux下ctags支持go语言的ctag工具
这里我主要讲一下Ctags这个程序。尽管ctags也可以支持其它编辑器ctags支持go语言,但是它正式支持的只有VIM。并且VIM中已经默认安装了Ctagsctags支持go语言,它可以帮助程序员很容易地浏览源代码。
熟练的使用ctags仅需记住下面七条命令ctags支持go语言:
1. $ ctags –R * ($ 为Linux系统Shell提示符)
2. $ vi –t tag (请把tag替换为您欲查找的变量或函数名)
3. :ts (ts 助记字:tags list, “:”开头的命令为VI中命令行模式命令)
4. :tp (tp 助记字:tags preview)---?此命令不常用,可以不用记
5. :tn (tn 助记字:tags next) ---?此命令不常用,可以不用记)
6. Ctrl + ]
7. Ctrl + T
在这里看全文
相关问答
Q1: erlang有没有好的ide推荐下
Erlang 开发的编辑器 一般就这几个: Sublime Text ,Eclipse,Idea,Vim,Emacs,ErlIde
Sublime Text,Vim,Emacs:Erlang语法高亮的,只是大型项目用的话,搜索相关的函数,只能全局搜索字符串的形式,好像Ctags支持Erlang,会有符号分析,但ctags支持go语言我几乎只有在写测试代码时候会用。
ErlIde:没使用过,你可以去了解下。
Eclipse:支持文件保存后自动编译,非常好。因为编译后,会马上发现错误,所以帮助你减少很多调试时间。然后支持查找函数调用情况(类似VS里的查找引用),这个在大项目里,非常有用的,比全局搜索字符串要高级一些。不好的情况是,会启动java虚拟机,比较耗资源ctags支持go语言;自动编译有时会失效,语法高亮有时会乱,就是感觉笨重点。
Idea:与Eclipse相比,支持代码补全(Eclipse有,有点卡),Rebar部署(Eclipse有),界面感觉很爽,不会启动java虚拟机,可以对erlang配置文件进行语法分析,不会偶尔出现一些小问题。唯一缺点就是她的自动编译很差劲,是全工程编译,非常慢,而且卡,暂时不支持单文件编译,所以很少有人用她的自动编译。
我个人非常推荐用Idea来写,但如果你对自动编译有需求,那可能用Eclipse好点吧。我自己用了半年多的Eclipse,然后公司让大家试试Idea,我觉得挺不错,后来就用Idea了。至于Idea自动编译的问题,我另外写了一个自动编译的程序。还有呢,Idea的Erlang插件,作者一直在维护更新的,这点是比较好的。
Q2: 如何在windows7下使用ctags
ctags(Generate tag files for source code)是vim下方便代码阅读ctags支持go语言的工具。尽管ctags也可以支持其它编辑器ctags支持go语言,但是它正式支持的只有VIM。并且VIM中已经默认安装了Ctagsctags支持go语言,它可以帮助程序员很容易地浏览源代码。
ctags能够定位如下内容ctags支持go语言:
1)用#define定义的宏
2)枚举型变量的值
3)函数的定义、原型和声明
4)名字空间(namespace)
5)类型定义(typedefs)
6)变量(包括定义和声明)
7)类(class)、结构(struct)、枚举类型(enum)和联合(union)
8)类、结构和联合中成员变量或函数
安装ctagsctags支持go语言,如果是RedHat,则直接使用yum命令安装:在指定的源码位置生成tags文件,并且我们添加很多参数来完善ctags的功能(为了体现其功能的强大,我用它来生成linux源码的tags文件):
然后我们查看tags内容就可以发现,原来tags就是linux内核代码中各个元素的索引,这也就是ctags结合vim可以快速进行定位的原因了(查询就是通过这个文件内容来定位的)。
Q3: 如何配置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'
\ }
Q4: ctags是一个什么工具阿?有什么作用呢?
ctags也可以支持其它编辑器,但是它正式支持的只有VIM。并且VIM中已经默认安装了Ctags
熟练的使用ctags仅需记住下面七条命令:(很简单吧,呵呵)
1. $ ctags –R * ($ 为Linux系统Shell提示符)
2. $ vi –t tag (请把tag替换为您欲查找的变量或函数名)
3. :ts (ts 助记字:tags list, “:”开头的命令为VI中命令行模式命令)
4. :tp (tp 助记字:tags preview)—此命令不常用,可以不用记
5. :tn (tn 助记字:tags next) —此命令不常用,可以不用记
6. Ctrl + ]
7. Ctrl + T
关于ctags支持go语言和go语言插件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








