VIM & CTAGS for Erlang
来源:互联网 发布:js url 汉字编码 编辑:程序博客网 时间:2024/05/17 09:07
VIM & CTAGS for Erlang
I pretty much only use VI(M) for coding and CTAGS is essential to increase productivity – It makes it easier to jump through files when I need to look at a function or where some variable has been declared, amongst other things. I have been using CTAGS for years when I was coding in C, Java and most recently PHP, Python and Erlang.
Here are the steps to enable CTAGS for Erlang on Mac OS X:
1) Install the latest version of Exuberant ctags
You need to install “Exuberant Ctags” which is an enhanced CTAGS implementation of the GNU CTAGS.
Exuberant ctags make it possible to jump to the definition of a class, method, variable and any other language object (e.g. C, C++, Python, PHP, Erlang) in vim. ‘ctags’ is able to generate an index file (a.k.a tags file) for one of41 supported programming languages. Index can be used by editors likevim to quickly find related keyword.
sudo port -v install ctags
2) Check installed version is correct (5.8)
ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert Compiled: Mar 6 2012, 23:30:52 Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net Optional compiled features: +wildcards, +regex
3) Check if the right ‘ctags’ is in the path
which tags
It should show:
/opt/local/bin/ctags
/opt is where Macports install bundles
4) Install Taglist VIM extension script:
Download taglist.zip and unzip the files to the $HOME/.vim
5) Go to the root of the project you want to generate CTAGS for
cd /projects/my_erlang_root_project_dir
6) Generate tags recursively
ctags --file-scope=no -R --languages=erlang .
7) Edit your .vimrc and add the following at the end
let Tlist_Use_Right_Window=1
let Tlist_Enable_Fold_Column=0
let Tlist_Show_One_File=1 " especially with this one
let Tlist_Compact_Format=1
let Tlist_Ctags_Cmd='/opt/local/bin/ctags'
set updatetime=1000
nmap ,t :!(cd %:p:h;ctags *)& " Maps the updates of tags to key ,t.
set tags=tags; " The ';' at the end will cause the ctags plugin to search for current dir and above dirs until it find a tag file.
" Add the following below if you want to generate ctags upon saving a file
" Auto-generate ctags upon making changes to a file
autocmd BufWritePost *.erl :silent !(cd %:p:h;ctags *)&
" If you want to auto compile (erlc) upon saving a file, then add that one as well
" Run erlc on the file being saved
autocmd BufWritePost *.erl :!erlc <afile>
8) Basic Usage
Basic usage boils down to 3 commands:
ctrl-] takes you to the declaration of a keyword your cursor is currently over. Jump is made so it doesn't matter in which file it is defined. Keyword is put on the tag stack. ctrl-t takes you a step back in the tag stack. ctrl-w w toggles the keywords list window.
Additional resources:
http://ctags.sourceforge.net/faq.html#15
http://www.zalas.eu/jumping-to-a-class-function-and-variable-definitions-in-vim-with-exuberant-ctags
http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
http://linux.byexamples.com/archives/385/vim-with-ctags-for-multi-level-directory-hierarchy/
http://ctags.sourceforge.net/
I use a gentags.sh script that I have customized a bit and put in my ~/bin – It generates tags in individual directories and I just run itinitially to create all the tags, then I use ,t key in vim to update the tags for a directory where I have modified/added/removed content in a source file or have it done automatically using the ‘autocmd’ explained above. If you want the gentags.sh file, let me know and I can make it available.
Happy Erlang Tagging!
- VIM & CTAGS for Erlang
- [vim] vim + ctags for "go to definition"
- ctags+taglist+cscope+VIM for C development
- VIM for windows + ctags + taglist + winmanager
- ctags for systemverilog(vim用)
- Setting up VIM for Erlang TDD
- vim ctags
- ctags+vim
- vim+ctags
- vim ctags
- 【vim】ctags
- ctags vim
- vim+ctags
- vim+ctags
- vim+ctags
- vim+ctags
- vim ctags
- vim ctags
- 63
- Enum和EnumSet的使用
- 读取ZIP文件
- Struts2 工作原理
- Android中Activity的新建和跳转
- VIM & CTAGS for Erlang
- 2D和3D游戏动作区分
- 【Ogre编程入门与进阶】第十一章Ogre启动序列(Startup Sequence)
- javascript学习总结五
- Hibernate基本概念和CRUD2
- Hibernate原理与应用
- 奇数因子
- Servlet Filter(过滤器)
- 一个悲情主义的大学生创业故事