Vim Plugin Introduction

Source: Internet
Author: User
Tags function definition key loop

工欲善其事, its prerequisite. A powerful development environment can greatly improve productivity. Well, I know it's nonsense ... However, I think there must be a lot of new developers like me who are going into the Linux platform, and at first it's frustrating to find a development tool that can be installed with a single click and almost flawless functionality, even if it's just a step back. Fortunately, with a few days of effort, I finally configured a fully functional vim-based development environment. In addition to the basic VIM, the development environment includes components such as Ctags,taglist,cscope,supertab,omnicppcomplete,winmanager,nerdtree and Minibufexplorer.

Before starting the operation, popularize the basic concepts and then contract the expression specification.

1) Vim has multiple configuration file vimrc, such as/ETC/VIMRC, which affects the vim of the entire system. And ~/.VIMRC, this file only affects the user's vim. And the configuration in the ~/.VIMRC file overrides the configuration in the/ETC/VIMRC. Here we only modify the ~/.VIMRC file.

2) Vim plugin (plugin) is installed in Vim's Runtimepath directory, you can run "set RTP" command under the VIM command line to view. Here we choose to install in the ~/.vim directory, without creating one.

3) When this article says "Run CMDXX command under the VIM command line", it means to run the CMDXX command in VIM's command line mode by entering a colon ":" into the command line mode in the normal mode of vim, followed by the input command cmdxx. The colon ":" input is omitted from the description later in this article.

4) If you do not specify "run a command under the VIM command line", the command is executed in the shell.

5) If the middle of the command is spaced or has characters that are easily confused with the text, I will use double quotation marks to distinguish the command from the body. So when the reader is actually working, do not enter the front and back quotes of the command.

6) This article on the combination of shortcut key description, shaped like a-B form of the shortcut key to the same time by pressing a key and the second key, and shape such as "A-C" form of shortcut keys, it means to press the A key and the B key at the same time, and then release the AB Key, and then press the C key.

1, installation using Ctags

Ctags tool is used to traverse the source code files generated tags files, these tags files can be used by the editor or other tools to quickly find the location of the source code symbols (Tag/symbol), such as variable name, function name and so on. For example, tags files are the basis for taglist and omnicppcomplete work.

The installation from the source package is described here, and the installation steps are the same as the source code installation steps for most software.

1) After downloading the source code package from http://ctags.sourceforge.net/, unzip the generated source code directory,

2) then go to the source code root directory to execute./configure,

3) then do make,

4) Execute make install after successful compilation.

5) Add the following line to the ~/.VIMRC:

Map <C-F12>:!ctags-r--c++-kinds=+p--fields=+ias--extra=+q .<cr>

To this, Ctags has been installed successfully.

The use of Ctags is also very simple. Enter our project code root directory and execute the following command: Ctags-r--c++-kinds=+p--fields=+ias--extra=+q.

In addition, because in the previous 5th, we have configured the CTRL-F12 combination shortcut in Vim, so we can also enter the code root directory, open vim, press the CTRL-F12 shortcut key to automatically generate tags file.

When the command finishes executing, the tags file is generated in the source code directory. Vim automatically reads the tags file in the current directory by default, so you do not need to modify the ~/.VIMRC file. At this point, we already have the ability to define jumps. Common shortcut keys are as follows:

1. $ Ctags–r *($ for Linux system shell prompt)2. $ vi–t Tag (please replace tag with the variable or function name you want to find)3.: TS (TS Mnemonic: Tags list, ":" Starts with command-line mode command in VI)4.: TP (TP mnemonic: Tags preview)5.: Tn (TN mnemonic: Tags next)6. Ctrl +] (jump to definition)7. Ctrl +T (back to jump)8.: Ta x (jumps to the definition of symbol X, if there are multiple symbols, jump directly to the first place9.: TS x (list symbol x's definition)Ten.: TJ X (can be considered as the merge of the above two commands, if only one symbol definition is found, then jump directly to the symbol definition, if there are multiple, then let the user choose) Note: When you run VIM, you must run in the current directory where the "tags" file is located. Otherwise, when you run vim, use the ": Set tags=tags;set tags+=your Path command sets the path to the "tags" file so that vim can find the "tags" file. In the completion of the code, you can manually delete the tags file (broom will not, dust off).

2, installation using TagList

TagList is a plug-in for vim that provides a structured view of source code symbols.

1) Download the installation package from http://www.vim.org/scripts/script.php?script_id=273, or download it from http://vim-taglist.sourceforge.net/index.html.

2) Enter the ~/.vim directory, unzip the TagList installation package, and after decompression will generate several new subdirectories in the ~/.vim directory, such as plugin and doc (additional directories may be created when other plugins are installed).

3) Enter the ~/.vim/doc directory and run "Helptags" under vim. Command. This step is to add the Help document under Doc to the VIM Help topic so that we can see the TagList help by running "Taglist.txt" in vim.

4) Open the configuration file ~/.VIMRC and add the following two lines:

[Plain]View Plaincopy
    1. Let tlist_show_one_file=1
    2. Let Tlist_exit_onlywindow=1

To this installation has been completed.

Run the Tlisttoggle command under the VIM command line to open the TagList window and run Tlisttoggle again to close it. The diagram is shown below:

We can switch focus between taglist window and edit area by ctrl-w shortcut or mouse click, select a symbol with the mouse or keyboard in the TagList window, then click or enter, you can jump to the position defined by the symbol.

More features are available by running the Help Taglist.txt query under the VIM command line.

3, installation using Cscope

Cscope provides interactive query language notation capabilities, such as querying where a variable is used or calling a function.

Cscope is already a standard feature of Vim and is supported by default, and the official website is http://cscope.sourceforge.net/.

1) Run version under Vim to see which features are supported by VIM, preceded by the prefix symbol + support. If Cscope is supported, go directly to 2), otherwise download the Cscope source code package to compile the installation. Step with Ctags installation.

2) After determining that Vim has supported cscope, download the file Http://cscope.sourceforge.net/cscope_maps.vim to the ~/.vim/plugin directory.

Here we can start using the cscope.

1) Use Cscope to generate Cscope database files. Go to the Project code root directory to run the command:

[Plain]View Plaincopy
    1. Cscope-rbq-f Path/xxx.out

The Xxx.out file, the Cscope database file, is generated when the command is run. For more usage refer to man cscope documentation.

2) Enter the project code root directory and run the command under VIM:

[Plain]View Plaincopy
    1. CS Add Path/xxx.out

This command loads the Cscope database into vim.

3) cscope Common shortcut keys

Ctrl-\ s finds all occurrences of the symbol where the current cursor is located.
Ctrl-\ C finds all functions that call the function where the current cursor is located.

Pressing the shortcut key will result in a list of search results below the edit area, enter the result number, and return to the corresponding location in the source code for the search result. For example, we move the cursor to the position defined by the initial_pool_size variable, that is, 17 rows, and then press the "Ctrl-\ S" combo shortcut to get the following diagram:

Then we enter 2, and enter, you can jump to the 2nd search results.

For a better view of the interface, you can export the Cscope search results to the Quickfix window, you need to add the following line in the ~/.VIMRC:

[Plain]View Plaincopy
    1. Set cscopequickfix=s-,c-,d-,i-,t-,e-

This way, when you find a symbol by using a shortcut key, you immediately jump to the position where the symbol first found appears. If you are not satisfied with the location of the default jump, run the CW command under the VIM command line to see the list of all results in the Quickfix window below the edit area, and click on the list item to jump to the appropriate location. This feature is already close to vs.:)

More features can be run by command man Cscope or by running the Help Cscope query under the VIM command line.

4, installation using Omnicppcomplete

The Omnicppcomplete provides hints and complements to the properties or methods of a class or struct in real time when input is provided. Like Talist, Omnicppcomplete is also a vim plugin, which also relies on the tags files generated with the Ctags tool. The installation steps are similar to TagList.

After downloading the installation package from http://www.vim.org/scripts/script.php?script_id=1520.

1) Enter the ~/.vim directory and unzip the installation version

2) Enter the ~/.vim/doc directory and run "Helptags" under the VIM command line.

3) Add the following lines to the ~/.VIMRC:

[Plain]View Plaincopy
    1. Set NOCP
    2. FileType plugin on

The use of Omnicppcomplete is almost identical to the VA under vs. As shown, enter M0. Immediately after the list of all the functions in the My_class class pops up, then use the up and down keys to select the appropriate function.

more features by running the "Help Omnicppcomplete" query under the VIM command line.

5, installation using Supertab

Supertab enables the tab shortcut key to have a quicker contextual hint function. Like Omnicppcomplete, Supertab is also a vim plugin.

Download the installation version from http://www.vim.org/scripts/script.php?script_id=1643. This installation package is different from the previous Vim plug-in, it is a VBA file, that is, the Vimball format installation package, this format installation package provides a way to install a dummy plug-in.

1) Open the. VBA installation package file with Vim.

2) Run the command "Usevimball ~/.vim" under the VIM command line. This command unzip the installation package to the ~/.vim directory. The convenience of Vimball installation is that you can open it in any directory. The VBA package is installed without switching to the installation destination directory. And you do not have to run the helptags command to install the Help documentation.

3) Add the following line to the ~/.VIMRC file:

[Plain]View Plaincopy
    1. Let g:supertabdefaultcompletiontype= "Context"

Supertab is very simple to use, as long as the input variable name or path name and other symbols by pressing the TAB key, you can get the previously entered symbol list, and through the TAB key loop selection.

6, installation using Winmanager,nerdtree and Minibufexplorer

The previous introduction of several tools and plug-ins, mainly provide quick editing functions, such as definition of jump, symbol query, symbol hint and complement. Here's the three plugins that are primarily optimized for the VIM layout of the interface. Specifically, Nerdtree provides a tree-like browse file system interface, Minibufexplorer provides multi-file simultaneous editing functions, and winmanager the Nerdtree interface and taglist interface integration, so that vim more similar vs!

Separate from http://www.vim.org/scripts/script.php?script_id=1658

http://www.vim.org/scripts/script.php?script_id=159

Http://www.vim.org/scripts/script.php?script_id=95

Download the Nerdtree,minibufexplorer and Winmanager installation packages (Winmanager also has an updated version of VBA http://www.vim.org/scripts/script.php?script_id= 1440, the old version of Winmanger is selected here).

1) Unzip the Nerdtree installation package to the ~/.vim directory, just like any other plug-in. And go to the doc directory and run "Helptags" under the VIM command line. Command.

2) Minibufexplorer only one. vim file, copy it to the ~/.vim/plugin directory.

3) Add the following lines to the ~/.VIMRC file:

[Plain]View Plaincopy
    1. Let G:minibufexplmapwindownavvim = 1
    2. Let G:minibufexplmapwindownavarrows = 1
    3. Let G:minibufexplmapctabswitchbufs = 1
    4. Let G:minibufexplmodseltarget = 1
    5. Let G:minibufexplmorethanone=0

4) Extract the Winmanager installation package to the ~/.vim directory.

5) Add the following lines to the ~/.VIMRC file:

[Plain]View Plaincopy
    1. Let g:nerdtree_title= "[Nerdtree]"
    2. Let g:winmanagerwindowlayout= "nerdtree| TagList "
    3. function! Nerdtree_start ()
    4. exec ' Nerdtree '
    5. Endfunction
    6. function! Nerdtree_isvalid ()
    7. Return 1
    8. Endfunction
    9. Nmap wm:wmtoggle<cr>

6) This version of Winmanager seems to have a small bug, when you open the Winmanager interface, you will open an empty file at the same time. This can affect subsequent use, so we'll turn off the empty file when we open the Winmanager. Locate the following function definition in the Winmanager.vim file in the ~/.vim/plugin directory and add the contents of line 6th below line 5th:

[Plain]View Plaincopy
    1. function! <sid>togglewindowsmanager ()
    2. If Iswinmanagervisible ()
    3. Call S:closewindowsmanager ()
    4. Else
    5. Call S:startwindowsmanager ()
    6. EXE ' Q '
    7. End
    8. Endfunction

Get here, and you're done!

Now enter our project directory, open vim, press the combination of shortcut keys w-m can be our new VIM! Press W-M again to close the interface. The diagram is shown below:

The top of the interface is a narrow edge is minibufexplorer, you can see I opened two files cache.c and assoc.c, is not much like the tag of the VS?

The rectangular area immediately below the Minibufexplorer is nerdtree. In this window, we can use the mouse or keyboard to easily browse the entire file system, click on a file or enter, you can edit the area on the right to open the file.

Below the Nerdtree is the TagList interface installed in the front.

7, other useful ~/.VIMRC settings

Set the color scheme, I use the eveing scheme, the color scheme is saved in/usr/share/vim/vimxy/colors

[Plain]View Plaincopy
    1. Colo Evening

Number of rows displayed

[Plain]View Plaincopy
    1. Set Nu

Options related to Auto indent

[Plain]View Plaincopy
      1. Set Autoindent
      2. Set tabstop=4
      3. Set shiftwidth=4
      4. P Set Mouse=a

Vim Plugin Introduction

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.