r5 - 02 Jun 2009 - 02:01:08 - Main.jisooyYou are here: TWiki >  Main Web > RtclMembers > JisooYang > JisooTechTips > JisooTechTipsVim

Vim/ctags/cscope tips

Inserting Escape (^[) character

Ctrl - v - [

Searching for C string constants in Vim

A simple, but incomplete, regular expression for C string constant is

\"[^"]*\"
It is incomplete because it can't handle '' \" '' in the string. Shown below is more refined version.
\"\([^"]*\\\"\)*[^"]*\"
For example, to find all C string and embrace them with S_S(), e.g., "Hello\n" to S_S("Hello\n"),
:1,$s/\"\([^"]*\\\"\)*[^"]*\"/S_S(&)/gc
Inversely, to remove the S_S() annotations,
:1,$s/S_S(\(\"\([^"]*\\\"\)*[^"]*\"\))/\1/gc

Generating ctags tag for Linux kernel

$ ctags -R --exclude=arch/powerpc --exclude=arch/ia64
                --exclude=include/asm-powerpc --exclude=include/asm-ia64

To use tags when in a sub directory, add the line below to .vimrc:

set tags=./tags, ./../tags., ./../../tags, ./../../../tags, ./../../../../tags

Using cscope with Vim

To generate a cscope database, in the source root directory execute
$ cscope -Rbkq
, where -R is to mean recursive, -b is to just build the database, -q is to create ''inverted index'', and -k is to indicate kernel mode so that no files in /usr/include is followed.

This command will create cscope.in.out, cscope.out, and cscope.po.out files in the source root.

To update the database later, just execute

$ cscope -U

" cs " is the Vim command for cscope operations. To add a cscope db,

: cs add path/to/cscope.out
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r5 < r4 < r3 < r2 < r1 | More topic actions

tip TWiki Tip of the Day
RSS news feed of topic changes
You can use an RSS news reader to find out what is new in a TWiki web. This complements WebChanges that ... Read on Read more

 
Home
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback