How to Use Vim ctags

Source: Internet
Author: User
Tags zip folder
In Windows, many people use source insight to write and view code. Vim can be used in Linux. At the beginning, VIM is considered as a notepad in windows. If it is used properly, it is not inferior to source insight. Here, I will do my best to explain in detail how to turn Vim into source insight, but you still need to think positively and explore something on your own. To avoid being too arrogant, I put the basic part behind it. If you think it is too simple, this article is not suitable for you; if you still have questions or do not understand what you are talking about, don't worry. There will be some necessary knowledge later. 1. Make good use of the built-in system software ctags. Most Unix systems have ctags, which can work well with vim. Purpose: generate a C-language Tag file to redirect between related C files. Usage: 1. generate the Tag file in the current directory (run the command after the $ prompt): $ ctags-R. -R indicates recursive and recursion. It generates a Tag file for the c file in the current directory and Its subdirectory. The last one is in the current directory. After running the current directory, one more file tags is the index file of the C tag. 2. jump 1) Use Vim to open a c file that has already been created. 2) Ctrl +] find the location where the cursor is located. 3) CTRL + t return to the previous tab. Note: Run Vim in the directory where the "tags" file is located. Otherwise, the "tags" file cannot be found. In vim, use the ": Set tags =" command to set the path of the "tags" file. For a slightly larger project, you may open Vim in any directory. However, generating a tags file in each directory is not a good idea. How can this problem be solved? The method is to add a line in. vimrc: Set tags = tags;/This indicates that Vim should go to the upper-level directory to find the tags file when it cannot be found in the current directory. 2. Additional installation scripts: 1. taglisthttp: // www.vim.org/scripts/script.php? Script_id = 273 if the address has changed during the download, go to www.vim.org to find the correct address, which is very simple. Purpose: After opening the source code, you can view the overall architecture of the source code for easy jump. (Those who are familiar with source insight must recall some of them) usage: download and install the plug-in. Enter the command tlist in VIM to open/close the taglist window. A simple method is to set the shortcut key and add a line in. vimrc: nnoremap <silent> <F8>: tlisttoggle <CR> so that you can press F8 in VIM to open/close the taglist. For more configurations, see Introduction to. vimrc. III. Basic Knowledge Conventions: For convenience and accuracy, we agree that the "$" command after the identifier is run on the terminal, and ": "The command is run in Vim. Vim configuration files are generally stored in the user's main folder, and $ Cd ~ is run on the terminal in non-root state ~ /The Directory to be accessed. The file name is. vimrc. Can't see it? There are two possibilities: 1. There is a dot in front of the file name, indicating that the file is hidden. You need to add the-A option when viewing the LS file. $ LS-A 2. You have not created the. vimrc file. Just create one by yourself. First, create an empty file. You can fill in the file continuously. $ Touch. vimrc there is also a. Vim folder under the main folder, please do not have your own mkdir $ mkdir ~ /. Vim in the. Vim folder, create two subfolders: plugin and Doc $ mkdir ~ /. Vim/plugin $ mkdir ~ The/. Vim/DOC plugin folder is used to place the plug-in, and the doc folder is used to place the corresponding help document. Go to the next taglist (should we call it a script or a plug-in? It is placed in the plugin folder, so it should be a plug-in; while in vim.org, it exists as a scripts, it should be a script .), Let's take an example. Download a zip package and place it in ~ /. Vim directory, and then $ unzip filename.zip folder has automatically put taglist.vimand taglist.txt In the plugin and Doc folders respectively. Restart Vim $ Vim to run the task. When tlist is run, it is found that there is no more column next to it? If you open a c file and have generated a tags file, some useful information should be displayed. At this time, the help document of taglist is already in ~ /. Vim/doc directory, but you have not responded to the help tlist command under vim, because Vim has not obtained the tag in the help document. The solution is in VIM: helptags ~ /. Vim/doc now, you can: Help tlist to see if there is any response? About. vimrc my own. vimrc is constantly improving. In the process of perfection, I got a lot of knowledge from the network. Thanks to the friends who provided the information, they also urged me to write this article. I paste part of my. vimrc below. You can add these to your. vimrc as needed. ". Vimrc """"""""""""""""""""""""""""""""""""""" "general """""""""""""" """""""""""""""""""""""""""""""""""""""" "For ctags, then it can find the 'tags' file even not in current directoryset tags = tags;/"Get Out of VI's compatible mode .. set nocompatible "sets how many lines of history Vim Har to rememberset history = 400" set to auto read when a file is changed from the outs Ideset autoread "have the mouse enabled all the time:" When you need to copy from vim, maybe you have ': set mouse = 'firstset mouse = """""""""""""""""""""""""""""""" "Colors and fonts """"""""""""""""""""""""""""""" "enable syntax highlightsyntax enable" set colorschemecolorscheme elflord "endif """"""""""""""""""""""" "Vim userinterface """"""""""""""""""""""" "Set 7 lines to the curors away from the border-when moving vertical .. set so = 7 "turn on wild menuset wildmenu" always show current positionset ruler "The commandbar is 2 highset Height = 2" show line numberset nu "set backspaceset backspace = EOL, start, indent "bbackspace and cursor keys wrap toset whichwrap + = <,>, H, l" show matching bracetsset showmatch "How many tenths of a second to blinkset MAT = 2" highlight s Earch thingsset hlsearch "imediately show the search resultset is """""""""""""""""""""""""""""" "folding """"""""""""""""""""""""""""""" "enable folding, I find it very usefulset nofenset FDL = 0 """"""""""""""""""""""""""""""" "text options """"""""""""""""""""""""""""""" "set expandtabset shiftwidth = 2 set ambiwidth = doubleset smarttab" Set Tab = 4 spacesset Ts = 4 set lbrset Tw = 500 set se Lection = intrusive "indent """"" "auto indent set ai" set auto indent width = 4 spaces set SW = 4 "smart indet set Si" C-style indenting set cindent "Usage: select codes, press '= 'key, the codes will autoindenting "Wrap lines set wrap" encoding settingsif has ("multi_byte ") "Set fileencoding priority if getfsize (expand (" % ")> 0 set fileencodin GS = ucs-bom, UTF-8, cp936, big5, EUC-JP, EUC-KR, Latin1 else set fileencodings = cp936, big5, EUC-JP, EUC-KR, latin1 endif "CJK environment detection and corresponding setting if V: lang = ~ "^ Zh_cn" "use cp936 to support GBK, EUC-Cn = gb2312 set encoding = cp936 set termencoding = cp936 set fileencoding = cp936 elseif V: lang = ~ "^ Zh_tw" "cp950, big5 or EUC-tw" are they equal to each other? Set encoding = big5 set termencoding = big5 set fileencoding = big5 elseif V: lang = ~ "^ Ko" "copied from someone's dotfile, untested set encoding = EUC-Kr set termencoding = EUC-Kr set fileencoding = EUC-Kr elseif V: lang = ~ "^ Ja_jp" "copied from someone's dotfile, unteste set encoding = EUC-JP set termencoding = EUC-JP set fileencoding = EUC-JP endif" detect UTF-8 locale, and replace CJK setting if needed if V: lang = ~ "Utf8 $" | V: lang = ~ "UTF-8 $" set encoding = UTF-8 set termencoding = UTF-8 set fileencoding = UTF-8 endifelse echoerr "sorry, this version of (g) vim was not compiled with multi_byte "endif """""""""""""""""""""""""""""""" "plugins """"""""""""""""""""""""""""""""" "tlistif & difflet tlist_auto_open = 0" Don't auto pen when compare two fileselselet tlist_auto_open = 1 "auto pen tlist when open a fileendif" set taglist window in right, delete the following line if you don't likelet tlist_use_right_window = 1let tlist_auto_update = 1 Let tlist_file_fold_auto_close = 1 "auto close tlist when exiting file. let tlist_exit_onlywindow = 1 NMAP <F7>: Copen <CR> NMAP <F6>: cClose <CR>
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.