Create vim+taglist+cscope+ctags combination editor under Ubuntu

Source: Internet
Author: User
Tags function definition function prototype parent directory


Some people complain that the Linux system does not resemble VC and other convenient and quick editor, someone with Gedit, some use vim, but are not convenient and there is no automatic completion of the user-friendly functions such as the user. This article briefly introduces the use of several plug-ins in Vim (Ctags, Cscope and TagList) to implement a powerful editor, hoping to help you learn and use. First, Software installation



Ubuntu provides us with a lot of convenience to install software, for example, the installation of Vim we can directly use the "sudo apt-get install vim" can be installed!



Similarly, cscope and ctags can also be installed in the same way, how refreshing it is! Thank you for the convenience of Ubuntu!






For TagList to be installed using this method, we need to download first and then install the complete:



First download the TagList plugin online, download the completion of decompression, and then the file under the TAGLIST.VIM using CP command Copy to the Home/.vim/plugin folder (Cp-r taglist.vim ~/.vim/plugin)



In this way, vim+taglist+cscope+ctags four tools we have installed, but how to use it?




second, Vim Introduction and Configuration



Vim is a very useful editing tool, and here are a few common bottom line mode commands:



(1). Set indent



: Set smartindent//Set Indent



: Set smartindent shiftwidth=4//C language Auto indent, indent value is 4 characters wide



(2). Display cursor row and column information



: Set ruler//display cursor information (lower right corner)



(3). View Tabs



: Set list//Display tab, with ^ symbol to show tab position



(4). View Line count Information



: Set number//Show line (left)



(5). Keyword highlighting



: syntax on//keyword highlighting



(6). Multi-file editing, you may need to edit multiple files while writing a program, in which case you need to set the following



: Split two.c//multiple file editing






Of course, if not too troublesome, you can open vim every time you enter the command, such as I often used is: set number:set ruler:syntax on:set smartindent command, if the usual in the bottom row mode entered the command directly to the configuration file, You do not have to enter these commands again when you use Vim later.



First of all, try the VI in the bottom line mode to enter the following command, if not supported, to download a full version of Vim, sudo apt-get install vim-full.



Here's how to modify a configuration file:



(1). Locate the VIMRC file.



(2) Permissions to view files:



zhouyl@ubuntu:~$ Cd/etc/vim
zhouyl@ubuntu:/etc/vim$ ls
VIMRC Vimrc.tiny
zhouyl@ubuntu:/etc/vim$ ls-l VIMRC
-rw-r--r--1 root 3449 September 17:30 VIMRC






(3) If you do not have write permission, modify the permissions so that we can modify the configuration file



sudo chmod a+w VIMRC
(4) Write the appeal command to the configuration file according to individual needs
For example, my personal settings are: syntax on, set ruler, set number, set Smartindent shiftwidth=4



The configuration information for my VIMRC file is attached below:





"Show line number
"set number" or set nu
map <F5> <Esc>: set nu <CR> "Map F5 to display line numbers, refer to" vim keymap "(http://www.pythonclub.org/vim/map-basic)
map <C-F5> <Esc>: set nonu <CR> "Map Ctrl + F5 to not display line numbers

"Detect File Type
filetype on

"Record History Lines
set history = 1000

"Automatic alignment
set autoindent
set cindent

"Smart Selection Alignment
set smartindent

"tab is 4 spaces
set tabstop = 4

"Use 4 spaces when interleaving between current lines
set shiftwidth = 4

"Set the matching mode, the right parenthesis will appear when you enter the parentheses
set showmatch

"Show cursor status while editing
set ruler

"Highlight Find
set hlsearch

"Paste Insert
set paste

"Quick Match
set incsearch

"Modify files for automatic backup
if has ("vms")
    set nobackup
else
    set backup
endif
"" "" "" "" "" "" "Settings on ctags" "" "" "" "" "" "" "
map <F4>:! ctags -R --c ++-kinds = + p --fields = + iaS --extra = + q. <CR> <CR>

"The semicolon in the first command is essential. This command makes vim first look for the tags file in the current directory.
The tags file, or if no corresponding target is found, it looks in the parent directory and recurs all the way up. Because the> path recorded in the tags file is always relative to the path where the tags file is located, the second setting item is used to change the current directory of vim.
set tags = tags;
set autochdir
"Absolute path
"set tags = / home / long / workstation / ganguio / uio-8139d-driver / V7 / tags, / home / long / linux-3.7.3 / drivers / uio / tags


"" "" "" "" "" "" "" "" "Taglist settings" "" "" "" "" "" "" "" "" "
map <F3>: Tlist <CR> "" Press F3 to call out
"let Tlist_Auto_Open = 1" After starting VIM, automatically open the taglist window
let Tlist_Ctags_Cmd = '/ usr / bin / ctags' "Set the position of ctags
let Tlist_Use_Right_Window = 0 "1 for the window to be displayed on the right, 0 for the window to be displayed on the left
let Tlist_Show_One_File = 0 "Enable taglist to display a list of functions of multiple files at the same time, set to 1 when not displayed at the same time> tags of multiple files, showing only the current file
let Tlist_File_Fold_Auto_Close = 1 "When displaying tags in multiple files at the same time, the taglist only displays the tags of the current file, and the function list of other files is collapsed and hidden
let Tlist_Exit_OnlyWindow = 1 "When taglist is the last split window, exit vim automatically
"let Tlist_Use_SingleClick = 1" By default, when you double-click a tag, it will jump to the position defined by the tag
"let Tlist_Process_File_Always = 0" whether tags are always processed. 1: processing; 0: not processing



"" "" "" "" "" "" "" "" "" "" "cscope settings" "" "" "" "" "" "" "" "" ""
set cscopequickfix = s-, c-, d-, i-, t-, e-
if has ("cscope")
set csprg = / usr / bin / cscope
set csto = 1
set cst
set nocsverb
"add any database in current directory
if filereadable ("cscope.out")
   cs add cscope.out
endif
set csverb
endif

nmap <C-@> s: cs find s <C-R> = expand ("<cword>") <CR> <CR>
nmap <C-@> g: cs find g <C-R> = expand ("<cword>") <CR> <CR>
nmap <C-@> c: cs find c <C-R> = expand ("<cword>") <CR> <CR>
nmap <C-@> t: cs find t <C-R> = expand ("<cword>") <CR> <CR>
nmap <C-@> e: cs find e <C-R> = expand ("<cword>") <CR> <CR>
nmap <C-@> f: cs find f <C-R> = expand ("<cfile>") <CR> <CR>
nmap <C-@> i: cs find i ^ <C-R> = expand ("<cfile>") <CR> $ <CR>
nmap <C-@> d: cs find d <C-R> = expand ("<cword>") <CR> <CR> 

Because the original configuration file in my document already has syntax highlighting:


"VIM5 and later versions support syntax highlighting. Uncommenting the next



"Line enables syntax highlighting by default."



If has ("syntax")



Syntax on



endif



So I did not write, you if the VIMRC file does not have this recommendation yourself plus syntax on set syntax highlighting






PS: In the configuration file "after the symbol content is a comment, and in the configuration file is not required to add a symbol, here about the Cscope, Ctags and taglist settings can be written first, the following will be the three plug-ins introduced." OK, now to open a vim, edit a program to see if it is not the general feeling.



Okay, here's the way to show the use of intelligent complement, I divided into four kinds of conditions: 1, the previous declared variable or function name complement, 2, structure, such as the completion of the construction, 3, STL, such as the completion of the standard library, 4, parentheses, quotes and other automatic matching completion.



For the first case, the process of writing a program, directly with the Ctrl+p can be selected, for the second case, if you want to declare the structure of T, want to be in the input T. Pop-up members to choose, just click before using: CTRL+F12, then the effect as shown:






Brief introduction and use of TagList plug-ins



TagList Plug-in, is a ctags based on the Vim Code window in the form of a split window (shown above) to display the current code structure overview, to increase the convenience of code browsing the Vim plug-in. After you load a code file in vim, you can use the following command to control TagList:



Tlistopen (direct tlist also can) open and input focus as to the Label List window, the effect is as shown above



Tlistclose Close Tag List window



Tlisttoggle Toggle Tab List Window status (open ←→ close), whether the Tab List window gets the focus depends on other configurations



Ctl-w+w or ctl-w+ arrow key window Toggle (TagList is essentially a vim separator window, so you can use the CTL-W series shortcut keys to the window to switch operations) in the TagList window mainly has the following operations



Press F1: Turn on Help enter: jump to the definition of the tag where the cursor is located (for example, move the cursor to the main function, press ENTER)



O: Create a new window and jump to the tag definition



P: Preview Tag definition (still in taglist window)



Spaces: A prototype that displays markup (such as a function prototype)



U: Update tag list (e.g. source file adds a function, and after saving, press U in taglist window)



S: Select sort field (for the moment I don't know what it means)



D: Delete the TagList file where the cursor is located (such as two files opened with VI f1.c,f2.c can delete f1.c tags)



X:n Enlarge/Shrink taglist window



+: Expand (refers to tags)



-: Folding



*: Full expansion



=: Collapse All



[[: Move the cursor to the beginning of the previous file



To move the cursor to the beginning of the following file



Q: Exit TagList window



F1: Turn off Help




Iv. Introduction and use of Ctags plug-ins



Ctags Introduction Vim is simple to use, we just look at vim from the Vitutor, about 20 minutes to master the use of Vim, above also briefly introduced the use of the point vim. But for programmers under Linux, C/s + +, using a combination of vim+ctags to write programs may be the best choice. ^_^ Although Ctags can support other editors, it officially supports VIM. And vim already has the default installed Ctags, it can help the programmer to browse the source code easily. Skilled use of ctags only need to remember the following seven commands: (very simple, hehe)



1. $ctags –R * ($ for Linux system shell prompt)



2.$ vi–t tag (replace tag with the variable or function name you want to find)



3. : TS (TS mnemonic: tagslist, ":" Command for VI command line mode command)



4. : TP (TP mnemonics: tagspreview)---This command is not commonly used, you can not remember



5. : Tn (TN mnemonics: tagsnext)---This command is not commonly used, you can not remember



6. CTRL +] Jump to the definition of the function or struct where the cursor is located



7. CTRL + T returns Find or jump



Here we explain the above command one by one: "$ctags –r*": "-r" means recursive creation and includes all subdirectories under the source code root (current directory). "*" indicates all files. This command will produce a "tags" file in the current directory, and will automatically load this tags file when the user runs VI in the current directory. The tags file includes a list of these objects: the definition of the value function of the macro enumeration variable defined by #define, the prototype and the Declaration namespace (namespace) type definition (typedefs) variable (including the definition and declaration) Class (class), struct (struct), Enum type (enum) and Union (Union) class, struct and union member variable or function VIM uses this "tags" file to locate the marked objects above. The rest of the command is the way to locate these objects: "$vi –t Tag": When running vim, add the "-T" parameter, for example: [/USR/SRC] $vim-tmain This command will open the file that defines "main" (variable or function or other) and position the cursor in this line. If this variable or function has multiple definitions, the VI command line mode ": TS" command lists a list for the user to choose from. ": TP" is the previous tag tag file, ": TN" is the next tag tag file.



Of course, if the current tags file in the user is looking for a variable or function name only one, ": tp,:tn" command is not available.



(The easiest way to do this is to move the cursor over the variable name or function name and press CTRL +] so that you can jump directly to the source file of the variable or function definition and position the cursor in that line.) Use "Ctrl+t" to return to the original place. Even if the user uses n times "CTRL +]" to find n variables, pressing n times "ctrl+t" can return to the original open file, and it will return on the original path. ^_^



Note: When you run VIM, you must run it in the same directory as the "tags" file. Otherwise, when running Vim also use ": settags=" command Set "tags" file path, so vim can find "tags" file. In the completion of the code, you can manually delete tags file (broom not to, dust will not run away ^_^).



Sometimes the system prompts "can't find tag" when not anxious, there is a possibility you want to query the function when the system function, if so, then you lucky, you can use Shift+k to query. If you are not not also can find tags file, open the query, if still can't find ... Hum, I have no other. Introduction and use of Cscope plug-ins



Cscope is a tool similar to ctags. You can think of it as being more than ctags, because it functions much more powerful than ctags. In Vim, a jump to a cscope query result is like jumping to a different label; it is stored in the tag stack. This allows you to easily jump between functions and so on, as with tags. Using Cscope in Vim is very simple:



First, use "CSCOPE-KQB" to generate Cscope.out files in the directory;



Use first in Vim's command line downward use "Cscope add/." /.. /cscope.out "(or CS Add/.. /.. /cscope.out) command to add a


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.