Build a visual C ++ editing platform for vim-general Linux technology-Linux programming and kernel information. The following is a detailed description. Vim is a powerful text editor. When we use VC to write code on the win32 platform, we often get used to some format control and code complementing functions provided by VC. These functions can be implemented in vim, A plug-in script has been written 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 habit of Unix source programs, we 'd better write programs 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. Therefore, because the default language of our system is zh_CN, a Chinese Date display is generated. 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 index source code files in many computer languages to be used by editors (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 description is as follows:
-- 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, which can be downloaded from vim official here: 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 function completion, there are also ready-made Plug-ins 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 running bash. 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 it. You can use type to check that our new command has taken effect:
Lf426 @ fleet :~ $ Type vctags
Vctags is aliased to 'ctags-R -- c ++-kinds = + p -- fields = + iaS -- extra = + Q'
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