Thursday, March 12, 2009

Linux - SET UP VIM CODING ENVIRONMENT

SET UP VIM CODING ENVIRONMENT
install vim or gvim
# sudo apt-get install vim-full or gvim
------------------------------
install cscope, ctags
# sudo apt-get install cscope global exuberant-ctags
------------------------------
download plugins
a) taglist.vim: http://www.vim.org/scripts/script.php?script_id=273
b) cppcomplete.vim: http://www.vim.org/scripts/script.php?script_id=527
c) gtags.vim: http://www.vim.org/scripts/script.php?script_id=893
d) cscope_maps.vim http://cscope.sourceforge.net/cscope_maps.vim
e) trinity.vim: (need screxpl.vim, NERD_tree.vim and taglist.vim )
http://www.vim.org/scripts/script.php?script_id=2347
edit .vimrc or _vimrc
nmap :TrinityToggleAll
nmap :TrinityToggleSourceExplorer
nmap :TrinityToggleTagList
nmap :TrinityToggleNERDTree
PS: there is a "space between and :

f) srcexpl.vim: http://www.vim.org/scripts/script.php?script_id=2179
g) NERD_tree.vim: http://www.vim.org/scripts/script.php?script_id=1658

put all plugins into $HOME/.vim/plugin
------------------------------
edit ~/.vimrc
set nu
set enc=utf8
set fenc=utf8
set tabstop=4
set browsedir=last
set nowrap
colorscheme murphy
syntax on

edit ~/.bashrc
set dspmbyte=utf8
------------------------------
write a script for stags and cscope
#!/bin/bash
if [ -n "$1" ]
then
cd $1 sudo find -name "*.h" -o -name "*.c" -o -name "*.cpp" > cscope.file
sudo cscope -bkq -i cscope.file
sudo ctags -Rb
# sudo ctags -R else echo "Please key-in path of project"
fi
PS: vim or gvim should be executed in the source code folder, otherwise cscope may not work
------------------------------
Useage:
ctags ctrl-] : find symbol
ctrl-t : go back to source
cscope
cscope的用法 :
cs find {querytype} {name}
{querytype}
c: find functions calling this function >> speed key:c
d: find functions called by this function >> speed key:d
e: find this eprep pattern >> speed key:e
f: find this file >> speed key:f
g: find this definition >> speed key:g
i: find file #including this file >> speed key:i
s: find this C symbol >> speed key:s
t: find assignments to >> speed key:t

trinity.vim
:Open and close all the three plugins on the same time
:Open and close the srcexpl.vim separately
:Open and close the taglist.vim separately
:Open and close the NERD_tree.vim separately

cscope -d : using the standalone Cscope browser
cscope -R
ctrl-d
# ctags -R 或是 ctags --recurse
ctags and vim :ta 與 :ts命令
------------------------------
others
http://cscope.sourceforge.net/cscope_vim_tutorial.html

FAQ:
if plugins not work, try this:
mkdir -p ~/.vim/plugin
cp ~/.vim/plugin

Reference from:
http://www.wretch.cc/blog/yenho/8773028