VimIntroduction
Source: http://www.cnblogs.com/Henrya2/archive/2009/02/21/1395584.html
Vim (VI improved) is a text editor similar to VI. It adds many new features and functions based on VI. With its powerful functions and customization capabilities, VIM has become one of the most important open-source editors (Emacs) in Linux/UNIX environments and is favored by many developers. The author uses the latest version 7.1.
Unlike most other editors, after entering vim, the characters entered by default are not inserted into the edited file. The Vim mode is very important. You need to know that Vim has the following modes:
1. normal Mode: the default editing mode. Unless otherwise specified, the commands mentioned are directly entered in normal mode; you can use the ESC key on the keyboard to return to normal mode in any other mode.
2. command mode: used to execute long and complex commands. In normal mode, enter ":" (General Command), "/" (Forward search), or "?" (Reverse search) to enter this mode. In command mode, enter the Enter key.
3. insert mode: used for text input. In normal mode, enter "I" (insert) or "A" (append) to enter the insert mode (there are other commands, for example, "C" can also enter the insert mode, but these commands have other functions ).
4. visual mode: used to select text blocks. In normal mode, you can enter "v" (lower case) to select text blocks by character, and input "v" (upper case) to select text blocks by line, or enter "Ctrl-V" to select by Square.
5. select mode: similar to the normal Windows Editor, select text blocks. After you select a text block in either visual or selection mode, you can use ctrl-g to switch to another mode. This mode is rarely used in Linux and will not be described in this article.
SetVimSyntax highlighting and automatic indent
Ii. Set the vim configuration file.
1. Configuration File Location
Under the/etc/Vim directory, there is a file named vimrc, which is a public Vim configuration file in the system and is valid for all users. In each user's home directory, you can create a private configuration file named ". vimrc ". For example, A. vimrc file already exists in the/root directory.
2. Set syntax highlighting
1) Open vimrc and add the following statement to highlight the syntax (Ocean Note: or cancel the annotation symbol before syntax on ):
Syntax on
2) If the syntax is still not highlighted, add the following statement to the profile file in the/etc directory:
Export term = xterm-color
3. Set Windows C/C ++ auto indent (Add the following set statement to vimrc)
1) set the (soft) tab width to 4:
Set tabstop = 4
Set softtabstop = 4
2) set the number of spaces for indentation to 4.
Set shiftwidth = 4
3) Set automatic indent: that is, the indent value of each line is equal to that of the previous line; Use noautoindent to cancel the settings:
Set autoindent
4) set the automatic indent mode in C/C ++ language:
Set cindent
5) set the specific indent mode for C/C ++ language (taking my windows style as an example ):
Set cinoptions = {s, T0, N-2, P2s, (03 S, =. 5 S,> 1 s, = 1 s,: 1 s
6) to display the line number of the text on the left, use the following statement:
Set nu
7) Add the following statement if it does not exist:
If & term = "xterm"
Set t_co = 8
Set t_sb = ^ [4% DM
Set t_sf = ^ [3% DM
Endif
[Transfer] http://hi.baidu.com/ti_tan/blog/item/8705e603155a64623812bbe7.html