Vim is a powerful text editor. We use VC to write on the Win32 platform Code Often, we are used to some of the format control and code complementing functions provided by VC. These functions can be implemented in Vim, and we have already prepared plug-in scripts for us, we can quickly build a C ++ compiling environment similar to VC with simple settings.
The Vim configuration file is usually in ~ /. Vimrc. First, we can add the following two sentences:
Syntax on // The syntax is highlighted, so we can see that the keywords of C/C ++ are colored;
: Set Cin! // Enable C indent. In this way, VIM automatically determines the indent settings;
After this setting is complete, when we create or open the C/C ++ source file that Vim can recognize, we can see the color of the keyword and automatic indent.
It should be noted that, according to the Unix Source Program We 'd better write the program in ASCII encoding, and Debian's internal encoding is UTF-8 by default. Of course, if the files created by VIM do not contain Chinese characters or other characters, the generated files are automatically ASCII encoded. However, some plug-ins, for example, the C-support plug-in of VIM automatically adds the file creation date. Because the default language of our system is zh_cn, a Chinese date is displayed. Therefore, a solution is to specify the language used when running Vim to create the CPP file, or simply create an alias for simple use:
Alias CVIM = 'lc _ all = C Vim'
This ensures that the created CPP file does not contain non-ASCII characters.
Next, let's take a look at ctags. In short, ctags are for many computer languages. Source code Files are indexed to be used by the editor (such as Vim. Let's first look at the help of ctags:
Ctags -- Help
The following information is used:
-R equivalent to -- recurse.
-- Recurse = [Yes | no] recurse into directories supplied on command line [No].
-- Ages = [+ |-] list
Restrict files scanned for tags to those mapped to langauges
Specified in the comma-separated 'LIST'. The list can contain in any
Built-in or user-defined language [all].
-- Fields = [+ |-] flags
Include selected extension fields (flags: "afmikklnss-1") [fks].
-- Extra = [+ |-] flags
Include extra tag entries for selected information (flags: "FQ ").
Run the following command in the directory where the source file is located: (for example, we can create an alias instance. We will discuss this issue at last)
Ctags-r -- C ++-kinds = + p -- fields = + IAS -- extra = + q
The parameter indicates the source of the original text.
-- C ++-kinds = + P: add the function prototype label to the C ++ file.
-- Fields = + IAS: Add Inheritance Information (I), access control information (a) of Class Members, and function fingerprint (s) to the Tag file)
-- Extra = + Q: Add a class modifier to the tag. Note: If this option is not available, the class members cannot be supplemented.
Now, the preparation is complete. First, we can use the C ++ object. Or-> to call the method, a select drop-down menu is automatically generated. The plug-in we need is omnicppcomplete. download it from the vim Official Website:
Http://www.vim.org/scripts/script.php? Script_id = 1, 1520
Download a compressed package and decompress it ~ /. Vim. In addition, we need ~ /. Open the Plugin in vimrc:
: Filetype plugin on
(You may need to enable Vim to identify the source code, but I didn't use it, Debian 4.0. If you need it, add: filetype indent on)
In addition, we close the default Vim preview window:
: Set completeopt = longest, menu
In this way, when an object is created, or-> is used, the selection window of class methods is automatically called up.
Another common complement is to complete functions, and there are also ready-made Plug-ins that can use code_complete:
Http://www.vim.org/scripts/script.php? Script_id = 1, 1764
This installation is simpler. Copy code_complete.vim directly ~ /. Vim/plugin.
To use the plug-in, when you write a function and enclose the left brackets (press the tab key to view the inverted function parameter list, including the overloaded function.
finally, we don't want to remember so many parameters. We just need to declare our two alias when Bash is running. In ~ /. Add the following to bashrc:
alias vctags = 'ctags-r -- C ++-kinds = + p -- fields = + IAS -- extra = + Q'
alias CVIM = 'lc _ all = C Vim '
shut down the terminal and restart, you can use type to check whether our new command has taken effect:
lf426 @ fleet :~ $ Type vctags
vctags is aliased to 'ctags-r -- C ++-kinds = + p -- fields = + IAS -- extra = + Q'