Post on 24-May-2015
Payton Chou2008/11/18
How to trace code like source insight through vim?
Vim hierarchy
• /etc/vim• |-- colors # theme• | `-- ir_black.vim• |-- doc # related intro.• | |-- SuperTabContinue.txt• | `-- Trinity.txt• |-- gvimrc # configure for gvim (vim-gnome)• |-- oldvimrc• |-- plugin # vim plugin• | |-- NERD_tree.vim• | |-- cscope_maps.vim• | |-- srcexpl.vim• | |-- supertab.vim• | |-- taglist.vim• | `-- trinity.vim• |-- vimrc # configure for vim• `-- vimrc.tiny # configure for vi
2EeePC SWRD Chi-Heng Chou
How to equip vim
• Install it– apt-get install vim vim-gnome exuberant-ctags
cscope• Modify your vimrc• The vimrc also effect the configure of gvim• Go to official site and put the vim plugin in
/etc/vim/plugin• Enjoy vimming
3EeePC SWRD Chi-Heng Chou
Basic setting of vim
• set showmatch " Show matching brackets.• set ignorecase " Do case insensitive matching• set incsearch " Incremental search• set mouse=a " Enable mouse usage (all modes) in
terminals• syntax on• set autoindent• set tabstop=4• set shiftwidth=4• set expandtab• set softtabstop=4• …
4EeePC SWRD Chi-Heng Chou
The killer of trace code tools
• Trinity (trinity.vim)– NERD_tree.vim
• file browser– srcexpl.vim
• source browser– taglist.vim
• class browser• Enhance of ctag
– cscope_maps.vim • symbol search tools
• Enhance Auto complete– supertab.vim
5EeePC SWRD Chi-Heng Chou
Advance setting of vim – font, theme, key mapping
• Font– set gfn=Consolas\ 12
• Theme– colorscheme ir_black
• Key mapping– Toggle taglist
• nnoremap <silent> <F12> :TlistToggle<CR>– Trinity: Open and close all the three plugins on the same time
• nmap <F8> :TrinityToggleAll<CR>– Trinity: Open and close the srcexpl.vim separately
• nmap <F9> :TrinityToggleSourceExplorer<CR>– Trinity: Open and close the taglist.vim separately
• nmap <F10> :TrinityToggleTagList<CR>– Trinity: Open and close the NERD_tree.vim separately
• nmap <F11> :TrinityToggleNERDTree<CR>
6EeePC SWRD Chi-Heng Chou
Advance setting of vim - devhelp
• " vim macro to jump to devhelp topics.• " --------------------------------------------• function! DevHelpCurrentWord()• let word = expand("<cword>")• exe "!devhelp -s " . word• redraw!• endfunction• " Example: bind <ESC>h to start devhelp and search for
the word under the• " cursor• nmap <ESC>h :call DevHelpCurrentWord()<CR>
7EeePC SWRD Chi-Heng Chou
Advance setting of vim – Search on line
• " online doc search• " --------------------------------------------• function! OnlineDoc()• let s:browser = "firefox"• let s:wordUnderCursor = expand("<cword>")• if &ft == "cpp" || &ft == "c" || &ft == "ruby" || &ft == "php" || &ft ==
"python"• let s:url = "
http://www.google.com/codesearch?q=".s:wordUnderCursor."+lang:".&ft• elseif &ft == "vim"• let s:url = "http://www.google.com/codesearch?q=".s:wordUnderCursor• else• return• endif• let s:cmd = "silent !" . s:browser . " " . s:url• execute s:cmd• redraw!• endfunction• map <ESC>k :call OnlineDoc()<CR>
8EeePC SWRD Chi-Heng Chou
How to use cscope?
Demo trace code through vim
• Supertab• Trinity• Online help• devhelp• ctag and cscope
– ctags * & cscope -R
9EeePC SWRD Chi-Heng Chou
Reference (1/3)
• My vim package– http://vip-file.com/download/8dd841907924/vim.tar.bz2.html
• vim的老家– http://vim.sf.net 或者 www.vim.org, 这里有很多 vim 的 tips 和 scripts
• vim的中文文档– http://vimcdoc.sourceforge.net/, 这里有 pdf格式下载 , 可以下载了慢慢看 .
• Best of Vim Tips– http://www.rayninfo.co.uk/vimtips.html– 在你询问某个技巧之前 , 先看看这篇 Best of Vim Tips,很有可能你就找到答案了 . 作者搜集整理了大量的 vim技巧 , 15 Years of Vi + 3 years of Vim and still learning ,作者这么说 .
– 那我们呢 ?vim的学习是无止境的 , 学的越多 , 你的效率就越高• VIM Quick Reference Card
– 这个对于新手很有用 , 也许刚开始你记不住那么多 vim的快捷键 , 没关系 , 打印一张卡片放在手边 , 忘记了可以看看 .
– http://tnerual.eriogerg.free.fr/vim.html, 这里有 pdf, dvi 和 tex格式的供下载• vim 新手指南
– vimtutor: vim内置的快速指南 , 强烈建议新手先看看这个交互式的入门教程– 执行方法 : vimtutor, 如果是windows, 在 vim的安装目录下也有一个 vimtutor.bat文件
• http://www.vi-improved.org/– 这里有给新手的一些建议 , 还有 vimrc 和 gvimrc的实例 , 稍作修改就可以为己所用 .
• Vim Cookbook– http://www.oualline.com/vim-cook.html
10EeePC SWRD Chi-Heng Chou
Reference (2/3)
• VIM Reference Card– http://www.linux.ie/articles/tutorials/vim-3.0.refcard.html
• http://www.pinkjuice.com/howto/vimxml/index.xml– 如果需要用 vim编辑 XML,看看这里的文章 Vim as XML Editor
• 如果需要用 vim编辑 LaTex,看看这里– http://vim-latex.sourceforge.net/
• 如果你需要 vim也能像 source insight一样的代码自动完成 , 可是试试这个 : Vim Intellisense– http://insenvim.sourceforge.net/– 它支持 c++,c#,java,JSP,xml,html 和 SQL种语言 , 依赖 perl .缺点是仅仅支持windows平台
• Vim 的杯子– http://www.cafepress.com/vimrefmug.25635024– 你没有看错 ,是 vim的杯子 ! 上面印着 Vim Reference ,不过一个需要 $10.99,看清楚 , 是美元
• color scheme– a) for JAVA– http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-java.html– b) for HTML– http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-html.html– c) for PERL– http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-pl.html– d) for LaTex– http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-tex.html
11EeePC SWRD Chi-Heng Chou
Reference (3/3)
• 最后强烈推荐水木社区 bbs 的 vim版面 : http://bbs.newsmth.net,那里面高手如云,是国内最好的有关 vim的专业版面。
• http://yurinfore.blogspot.com/2008/11/vim-google-code-search.html
• http://blog.roodo.com/thinkingmore/archives/7515251.html
• http://bhoadmin.blog.sohu.com/99498576.html
12EeePC SWRD Chi-Heng Chou
•Thanks for your kind attention
13EeePC SWRD Chi-Heng Chou