Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctag database for Go

Tags:

How to generate tags file for Go source

In mac, I installed exuberant ctags , and tried the below command in source directory

ctags -f gosource.tags -R `pwd` 

But, it doesn't consider *.go files. Do I have to use -h option? But, isn't it only for header files, as per the manual?

Please give me the correct command so that I can use the tags file with vim. I also prefer absolute path so that I can keep the file anywhere

Thanks.

Edit: I assumed current ctags support Go, seeing http://groups.google.com/group/golang-nuts/browse_thread/thread/3a4848db231b02c9.

but, http://ctags.sourceforge.net/languages.html desn't have go listed.

like image 541
bsr Avatar asked Nov 20 '11 20:11

bsr


People also ask

Does ctags work with C++?

Ctags is a program that generates a tag (or index) file of objects and functions found in C/C++ header and source files. The tag file allows these items to be referenced quickly from within UltraEdit.

What is ctags Vim?

Ctags is a tool that will sift through your code, indexing methods, classes, variables, and other identifiers, storing the index in a tags file. The tags file contains a single tag per line. Depending on command line arguments and the language ctags is run against, a lot of information can be obtained from this index.

What is exuberant ctags?

Exuberant Ctags (e-ctags) maintained by Darren Hiebert, the ancestor of Universal Ctags, improved traditional ctags with multi-language support, the ability for the user to define new languages searched by regular expressions (called optlib in Universal Ctags), and the ability to generate emacs-style TAGS files.


1 Answers

Add the following to ~/.ctags

--langdef=Go --langmap=Go:.go --regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)/\2/d,func/ --regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/d,var/ --regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/d,type/ 

(From http://go-wise.blogspot.com/2011/09/using-ctags-with-go.html)

like image 76
lazy1 Avatar answered Sep 19 '22 17:09

lazy1