ºìÁªLinuxÃÅ»§
Linux°ïÖú

viÖнáºÏctag²éÕÒº¯ÊýÉùÃ÷

·¢²¼Ê±¼ä:2007-11-28 00:29:21À´Ô´:ºìÁª×÷Õß:wmbodbc
±¾ÈËÒÔÇ°×öwindows·½Ã濪·¢£¬ÔÚwindowsÏÂÃæд´úÂë´ó¶àÒÀ¿¿¹¦ÄÜÇ¿´óµÄ¼¯³É¿ª·¢»·¾³IDE£¬Èç΢ÈíµÄVisual studio ϵÁУ¬IBMµÄEclipse, BorlandµÄJBuilder,DelphiµÈµÈ¡£ÏÖÔÚͻȻתµ½LinuxÏ£¬Ê¹ÓÃviµÄ¸Ð¾õºÜ²»×ÔÔÚ£¬±ÈÈçÒ»¸ö*.cÎļþÖÐÒýÈëÒ»´ó¶ÑµÄ.hÎļþ£¬ ÔÚÕâ¸ö*.cÎļþÖУ¬Ê¹ÓõÄij¸öº¯Êýfunction(param1,param2),²»ÖªµÀÊÇÄĸöÎļþÖÐÉùÃ÷µÄ¡£´ËʱÈç¹ûÊÇÔÚwindowsƽ̨Ï£¬Ê¹ ÓÃÈκÎÒ»¿îIDE¶¼Äܷܺ½±ãµÄÌøתµ½º¯ÊýÔ­ÐÍ´¦£¬µ«ÔÚLinuxϾͲ»ÊÇÄÇÑùµÄ·½±ãÁË£¬´ËʱËäȻҲ¿ÉÒÔʹÓÃgrep£¬µ«»¹ÊÇÓе㷳ÈË¡£

Çë½ÌͬÊ£¬ËûÃÇÓõÄÊÇCtag£¬´ÓÍøÉÏÏÂÔØexuberant-ctags£¬°²×°ºó£¬Ê×ÏÈ£¬ÔÚÔ´Âë¸ùĿ¼´¦½¨Á¢tagsÎļþ£¬Ö¸ÁîÈçÏ£ºCtag -R
´ËʱÔÚµ±Ç°Ä¿Â¼Ï¾ʹ´½¨ÁËÒ»¸ö½ÐtagsµÄÎļþ¡£
µÚ¶þ.ʹÓÃvi´ò¿ª*.cÎļþ£¬Èç¹ûÏë²é¿´function(param1,param2)ÔÚ¶àÉٵط½ÒýÓÃÁË»òÕßÔÚʲôµØ·½ÉùÃ÷µÄ£¬¿É½«¹â±êÒƵ½ÉÏ˵µÄº¯ Êý´¦£¬ÔÚviµÄÃüÁî·û״̬ÊäÈ룺tag function£¨»òÕßÖ±½Ó°´ CTL£«£ý£©,vi½«Ìøתµ½ÕÒµ½µÚÒ»¸öfunctionµÄ*.cÎļþ»ò*.hÎļþÖС£
µÚÈý.ÈçÏë¿´¿´µ½µ×ÓжàÉÙÎļþÒýÓÃÁ˸ú¯Êý£¬¿ÉÔÚviÃüÁî·û״̬ÊäÈë:ts,¾Í¿ÉÒÔ¿´¼ûÓжàÉٵط½Ê¹ÓÃÁ˸ú¯Êý¡£
µÚËÄ.°´CTL£«T¼ü½«·µ»Øµ½Ô­À´µØ·½¡£

vi+indent+ctag±à¼­c

vim½áºÏctag£¬indentÊDZȽϺõÄÓÃÓڱ༭£¬²é¿´cÓïÑÔÔ´³ÌÐòµÄ·½·¨¡£
ctagÍê³ÉÎļþ¼äÔªËؽ»²æ¹ØÁª¡£
ctag -R *
:ta ±êÖ¾·û
ctrl+]
ctrl+o
ctrl+t
vi -t ±êÖ¾·û
indentΪԴ´úÂë½øÐиñʽ»¯¡£
:%!indent



˵˵ÔÚfedoraÉÏʹÓÃctagsºÍcscope¿´´úÂë

ÎÒ×°µÄfedora6ÉϵÄvim°æ±¾ÊÇ7.0£¬´øÓÐ ctags-5.6ºÍ cscope-15.5µÄÖ§³Ö¡£ÎÒÑ¡ÔñÁ˹¤×÷»úʹÓÃlinux fedora6£¬ÏµÍ³×Ô´øµÄwordºÍ¿´pdfÎļþµÄÈí¼þ¶¼ÓУ¬ÊÕ·¢ÓʼþµÄÈí¼þÒ²ÓУ¬Í¦·½±ãµÄ£¬ºÃÓ㬾ÍÊÇ¿´´úÂëµÄÈí¼þÐèÒª×Ô¼ºÅäһϣ¬Âé·³Ò»µã£¬²»¹ýÅä ºÃÁËÒÔºó´ÓËٶȺÍʹÓÃÏ°¹ßÉϱÈsourceinsightºÃʹ¡£²Î¿¼ÁËÍøÉÏһЩÈ˵ľ­Ñ飬ʵ¼ùÁËһϣ¬Ð´Õâ¸öÎĵµ×ܽáÒ²Ðí¶ÔÏëÁ˽âÁ˽âctagsºÍ cscopeµÄÈËÓаïÖú¡£

Óкܶà³ÌÐòÔ±ÔÚlinuxÉÏÏ°¹ßʹÓÃvi±à¼­Æ÷£¬Ò²ÓÐһЩÈËϲ»¶Ê¹ÓÃemacs£¬²»¹ýÎÒ¸öÈË»¹ÊÇÇãÏòÓÚvi£¬ÆäʵÓùßÁËvi¾Í²»Ï²»¶Óà windowsÉϵı༭Æ÷ÁË£¬ÆäʵԭÒòºÜ¼òµ¥£ºÊ¹ÓüüÅÌÍê³É²éÕÒºÍÌæ»»±ÈÓÃÊó±ê׼ȷºÍ¿ì£¬¶øvi¶¼Ê¹ÓüüÅ̲Ù×÷ʵÏÖ¹¦ÄÜ¡£Ä¿Ç°vimÊÇÀàËÆÓÚviµÄ±à¼­ Æ÷£¬ËüÊÇ¿ªÔ´ÏîÄ¿¶øÇÒ¹¦Äܸü¶à£¬¶øctagsºÍ cscope¾ÍÊÇËüµÄ²å¼þ£¬ÏÂÃæÕë¶Ôvim À´Ì¸Ì¸ÅäÖÃʹÓÃctags ºÍcscope¿´´úÂë¡£

1¡£ÐèÒªÏÂÔØ°²×°

taglistÊÇvimµÄ²å¼þ£¬ÓÃÀ´ÔÚÆÁÄ»×ó±ß¿ª´°¿ÚÏÔʾ´úÂëµÄÈ«¾Ö±äÁ¿¡¢º¯ÊýÃû³Æ

ÏÂÔصØÖ·£ºhttp://www.vim.org/scripts/script.php?script_id=273

ÎÒÏÂÔصÄÊÇtaglist-43.zip

°²×°µÄ·½·¨Êǽ«Õâ¸ö°üÔÚ/usr/share/vim/vim70ÏÂÕ¹¿ª


2¡£¶ÔÓ¦ÐèÒª¿´µÄ´úÂëÉú³ÉcscopeµÄÊý¾Ý¿â£¬Õâ¸ö¹ý³ÌÒ²½ÐѵÁ·

ÎÒÐèÒª¿´µÄ´úÂëÓÐÈý²¿·ÖÒ»²¿·ÖÊÇlinuxÄںˣ¬ÁíÍâÁ½¸ö²¿·ÖÊÇ¿âºÍÓ¦Óòã´úÂë¡£

LinuxÄں˴úÂëÕë¶ÔÎÒÐèÒªµÄ²¿·ÖÕûÀí³öÊý¾Ý¿â£¬¶ø²»Ïà¹ØµÄ²¿·Ö²»²Î¼ÓÕûÀí

ÏȽ¨Â·¾¶:

mkdir $HOME/readcode

mkdir $HOME/readcode/cscope-kernel

mkdir $HOME/readcode/cscope-app

½øÈë·¾¶£º

cd readcode

½¨Á¢Éú³Écscope Êý¾Ý¿âµÄÎļþÎļþÃûÊÇcreate-kernel.sh

LNX=$HOME/build/linux-2.4.22

find $LNX \

-path "$LNX/arch/*" ! -path "$LNX/arch/arm*" -prune -o \

-path "$LNX/include/asm-*" ! -path "$LNX/include/asm-arm*" -prune -o \

-path "$LNX/tmp*" -prune -o \

-path "$LNX/Documentation*" -prune -o \

-path "$LNX/scripts*" -prune -o \

-name "*.[chxsS]" -print >$HOME/readcode/cscope-kernel/cscope.files

cd $HOME/readcode/cscope-kernel

cscope -b -q -k

cd $HOME/readcode

Ö´ÐÐ source create-kernel.sh

»áÔÚĿ¼$HOME/readcode/cscope-kernelÏÂÉú³Écscope.outÎļþ

¶ÔÓ¦Óòã´úÂëÉú³ÉcscopeµÄÊý¾Ý¿âÒª¼òµ¥µØ¶à

ËüµÄÉú³É½Å±¾£º

APP=$HOME/build/App

find $APP -name "*.cpp" -print >$HOME/readcode/cscope-app/cscope.files

find $APP -name "*.[ch]" -print >>$HOME/readcode/cscope-app/cscope.files

cd $HOME/readcode/cscope-app

cscope -b -q -k

cd $HOME/readcode

Ó¦ÓóÌÐò´úÂëÓÐһЩÊÇc++µÄ£¬ËùÒÔ½«.cpp¸ñʽµÄ´úÂëÁгöÀ´Éú³ÉcscopeÊý¾Ý¿â


3¡£ÅäÖÃ.vimrcÎļþ

.vimrcÄÚÈÝÈçÏ£º

set cst

set csto=1

set cscopequickfix=s-,c-,d-,i-,t-,e-,f-

cs add /home/yangxl/readcode/cscope-kernel/cscope.out

cs add /home/yangxl/readcode/cscope-app/cscope.out

let Tlist_Enable_Fold_Column = 0

let Tlist_WinWidth = 30

let Tlist_Show_One_File = 1

set tabstop=4

nmap :cs find d =expand("")

nmap :cs find c =expand("")

nmap :cs find t =expand("")

nmap :cs find e =expand("")

nmap :cs find f =expand("")

nmap :cs find i =expand("")

nnoremap :TlistToggle

×îÏÂÃæÕ⼸Ðж¨ÒåÁËF2-F9¹¦ÄܵĿì½Ý¼ü

F9ÊÇ´ò¿ª¹Ø±Õ×ó±ßtaglist´°¿ÚµÄ¿ì½Ý¼ü

¾ßÌåËüµÄÓï·¨½âÊÍÔÚviÖÐͨ¹ý¼üÈë

:help cscope

ѧϰºÍÀí½â


4¡£Ê¹Ó÷½·¨

ÓÃvi´ò¿ª²Î¼ÓѵÁ·µÄ´úÂ룬½«¹â±êÍ£ÁôÔÚµ÷Óõķ½·¨ÉÏ°´ctrl-], ÊDz»ÊdzöÏÖÁËÕâ¸ö·½·¨µÄÔ­ÐÍ´úÂ룬°´F9¼ü¶à³ö×ó±ß´°¿Ú£¬ÏÔʾ·½·¨ÃûÁбíºÍºê¶¨ÒåºÍÈ«¾Ö±äÁ¿£¬ÔÙ°´Ò»´ÎF9×ó±ß´°¿ÚÏûʧ¡£

ÏÔʾ¼ÓÔصÄÊý¾Ý¿â

£ºcs show

ÄÜ¿´µ½¼ÓÔØÁËÁ½¸öcscope.outÎļþ

:cs find 2 ·½·¨Ãû »ò :cs find d ·½·¨Ãû ¶ÔÓ¦¿ì½Ý¼üF2

Íê³ÉÕÒµ½±»Õâ¸ö·½·¨µ÷Óõķ½·¨Ãû

:cs find 3 ·½·¨Ãû »ò :cs find c ·½·¨Ãû ¶ÔÓ¦¿ì½Ý¼üF3

Íê³ÉÕÒµ½µ÷ÓÃÕâ¸ö·½·¨µÄ·½·¨Ãû

:cs find 4 ×Ö·û´®Ãû³Æ »ò :cs find t ×Ö·û´®Ãû³Æ ¶ÔÓ¦¿ì½Ý¼üF4

ÕÒµ½³öÏÖµÄ×Ö·û´®

:cs find 7 ÎļþÃû »ò :cs find f ÎļþÃû ¶ÔÓ¦¿ì½Ý¼üF7

ÕÒµ½Îļþ

:cs find 8 ÎļþÃû »ò :cs find i ÎļþÃû ¶ÔÓ¦¿ì½Ý¼üF8

ÕÒµ½includeÕâ¸öÎļþµÄÎļþ

:TlistToggle ¶ÔÓ¦¿ì½Ý¼üF9

5¡£Ã»ÓÐ×öµ½µÄ

¿¼ÂÇ´úÂëÔÚ²»¶ÏµÄ±àд¹ý³ÌÖУ¬ÔõÑù×ö²ÅÄÜͬ²½cscopeµÄ¿âÄØ£¿
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. vicar ÓÚ 2007-11-29 20:44:01·¢±í:

    :0()w(1 ÓÃÐľÍÓÐ