Who said Vim is not an IDE? (4)

Source: Internet
Author: User

Series 4 introduces how to use VimCodeBrowsing, indexing, Tag, Tag, search, and other functions, including ctags, taglist, and visualmark, especially ctags, are the basis of various plug-ins in the future. It is better to be proficient in understanding and understanding. Enter the text below:

Ctags1,

Http://ctags.sourceforge.net

2. Function Description

Strictly speaking, ctags are not Vim plug-ins, but label commands in Linux/Unix. PassCtags-RCommandSource codeAnd generate an index file. Vim uses the Tag file generated by ctags to implement common code jump functions in IDE. It is a handy tool for home travel code indexing. Ctags not only supports static languages such as C, C ++, and Java, but also supports dynamic scripting languages such as Python, Perl, PHP, and JSP, ctags basically do not support objective-C, and it also has poor support for Ruby. With the popularization and development of these languages, we hope that the ctags of subsequent versions willProgramming LanguageBetter support.

3. Installation

For Ubuntu, run the following command:Sudo apt-Get install ctagsAfter the installation is complete, enterCtags -- HelpAnd the normal help information indicates that the installation is successful.

For Mac users, OS X comes with the ctags command, but this is not the ctags required by VIM. You need to reinstall it:Sudo port install ctags. Because the ctags of OS X are located in the/usr/bin directory, they are generally preferentially loaded in the path. Therefore, after installation, you need to set the environment variable, make sure that you are using the newly installed ctags on the command line. If no special settings are made, the installed ctags are generally under/opt/local/bin, and the following code is added to the current user's. Profile:Export Path =/opt/local/bin/: $ path, Executed on the terminalSource. ProfileIt takes effect immediately.

4. Instructions for use
    • Create a tag Index
      As mentioned above, ctags are mainly used to create tag index files that can be used by VIM.Ctags-RYou can recursively create an index file for the code in the current directory. The file is saved in the current directory. The default file name is tags. The file size depends on the amount of code you want to index.
      To specify the location of the Tag file and the location of the index code, run the following command:
      Ctags-r-o ~ /. Vim/ctags/pythontags/somepythondir/

    • Set the index file location
      Vim needs to know the location of the tag index file during running. If it is not specified, VIM will find the file named tags in the current directory as the tag index file.
      If you want to use the index file in a directory, start Vim in the directory. You can also set or change the index file location through the following command after startup:
      Set tags =/home/XXX/XX/tags, xxxx/tags ,......

Of course, you can also write this command to. vimrc.

    • Use tags in VIM
      After the index file and location of the tag are set, everything is ready. Now we can use the tag in VIM for code jump and tracking.
      Ctags mainly indexes the classes, methods, variables, and other elements in the source code. Therefore, if we remember a class name, method name, or variable name, if you want to directly open a file hidden in the depth of a stacked directory under the command line, the following command can help us implement this function:
      Vim-t class | method | variable
      For example, to open a file that contains the loadcache method, run the following command:
      Vim-T loadcache
      If multiple files contain the loadcache method, VIM opens the first file by letter. To view other files, run the TS command,: TSAll files containing the loadcache tag are listed. You can enter the file serial number to open the file and locate the loadcache tag. You can scroll up and down through J and K.

If you only use the vim command to open a file, you can use the following command to search and browse the file:

 
: Ta tagname jump to the location defined by tagname: stag tagname in the split window to view the file containing tagname: tags to view the path of the tag to the current location: TS tagname lists tags matching the tagname. If it is null, use the last tag in the tag Stack: TF to jump to the first matched Tag: TL to the last matched tag.

Jump shortcut:

 
CTRL-]: Jump to the definition of the object where the cursor is located. CTRL-T: return the value of [N] Ctrl-T: [N], which is a number and jumps back n times; equivalent to repeated n Ctrl-T operations
5. Notes

Make sure that Vim can find the tags file when opening the file.

Taglist1,

Https://github.com/vim-scripts/taglist.vim

2. Function Description

Taglist is a code browser plug-in of VIM, similar to the Outline View in IDE, the code in different languages can display the packages, classes, interfaces, methods, functions, variables, attributes, and other content in the Code. It is a necessary tool for VIM to browse the code.

 

Taglist also relies on the ctags command to generate tags.

3. Installation
    • Enter~ /. Vim/bundleDirectory
    • Run:Git clone git: // github.com/vim-scripts/taglist.vim.git

    • In. VimrcFile Settings taglist configuration information, the following is my preference settings

      "Taglist {Let tlist_show_one_file = 1" only displays the taglist of the current file. Multiple let tlist_exit_onlywindow = 1 is displayed by default. "If taglist is the last window, exit Vim let tlist_use_right_window = 1 "and display the taglist let tlist_gainfocus_on_toggleopen = 1" in the right window, the cursor is retained in the taglist window let tlist_ctags_cmd = '/opt/local/bin/ctags' "To set the location of the ctags command nnoremap <leader> TL: tlist <CR> "setting shortcut keys for closing and opening the taglist window "}
4. Instructions for use

According to your preferences. VimrcSettings:

    • Tlist_ctags_cmd: Specifies the location of the ctags command.
    • Tlist_use_horiz_window: When set to 1, the taglist window is displayed horizontally. Default vertical display
    • Tlist_winheight: Set the width of the taglist window.
    • Tlist_winwidth: sets the height of the taglist window.
    • Tlist_show_one_file: if the value of tlist_show_one_file is set to 1, only the taglist of the current file is displayed. By default, tags in multiple files are displayed.
    • Tlist_sort_type: by default, taglish is sorted by the order in which tags appear in files. It is set to "name", and taglist is sorted by Tag name.
    • Tlist_exit_onlywindow: When set to 1, if taglist is the last window, exit Vim
    • Tlist_use_right_window: When the value is set to 1, the taglist window appears on the right and is displayed on the left by default.
    • Tlist_auto_open: If you want to automatically open the taglist window after Vim is started, set this parameter to 1.
    • Tlist_close_on_select: If you want to automatically close the taglist window after selecting a tag, set this parameter to 1.
    • Tlist_gainfocus_on_toggleopen: When set to 1, open the taglist cursor and keep it in the taglist window.

When you use Vim to openProgramFile, we can use: TlistOpen the taglist window. If the program has classes, interfaces, attributes, and other elements, it will be displayed in the taglist window. You can use the following common shortcut keys to operate the taglist:

    • By selecting a tag with the cursor, you can press enter to jump to the program location that defines the tag.
    • Press the Space key when you select a tag. The complete definition of the tag is displayed below the status bar.
    • X to zoom in or out the taglist window horizontally.
    • =, Fold all tags
    • +, Open all tags
5. Notes

Confirm in. VimrcUse tlist_ctags_cmd to define the location of the correct ctags command. Otherwise, the tag cannot be found.

Visualmark1,

Http://www.vim.org/scripts/download_script.php? Src_id = 1, 4700

2. Function Description

Visualmark, as its name implies, is to quickly tag and switch back and forth when you read or write code.

3. Installation

In. Vim/bundleCreate a folderVisualmark/pluginCopy the downloaded file visualmark. Vim to this folder.

4. Instructions for use

Use Vim to open a file and use the shortcut keyMmSet the tag. You can switch up and down browsing through F2 and SHIFT + F2.
We can also customize the label style:
Open visualmark. vim and find the following code:

// Set the label color based on the background color, cterm indicates that if & BG = "dark" highlight signcolor ctermfg = white ctermbg = blue guifg = white guibg = peruelsehighlight signcolor ctermbg = white ctermfg = red guibg = gray guifg = royalblue3endif
5. Notes

None

 

Happy every day ()

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.