Gradually set Vim C/C ++ syntax highlighting and automatic indent

Source: Internet
Author: User
Vim(VI improved) is a text editor similar to VI, which adds many new features and functions based on VI. Vim has become a Linux/Unix environment with its powerful functions and customization capabilities. Open SourceOne of the most important editors (the other is Emacs), which 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 and default editing mode; if no special instructions are added below, all the commands mentioned are directly input 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) and "/" (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, type "I" (insert) or "A" (append) you can enter the insert mode (there are also some commands, such as "C", you can also enter the insert mode, but these commands have other functions ). 4) visible (visual) mode, used to select text blocks; you can enter "v" (lower case) in normal mode to select by character, and enter "v" (upper case) or press 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.

USetVimSyntax highlighting and automatic indentGfklinux Alliance

Ii. Settings Vim Configuration File 1 , Configuration file locationUnder the/etc/directory, there is VimrcFile, 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, in the/root directory, . VimrcFile. 2 Set syntax highlighting1) Open vimrc and add the following statement to highlight the Syntax: syntax on2) if the syntax is still not highlighted, add the following statement to the profile file in the/etc directory: export term = xterm-color 3 , Settings Windows Style C/C ++ Auto indent (Add the following Set Statement Vimrc Medium)1) set (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 setting: Set autoindent 4) set the automatic indent mode in C/C ++ language: Set cindent 5) set the specific indent mode of C/C ++ language (take my windows style as an example): Set cinoptions = {s, T0, N-2, P2s, (03 S, =. 5 S,> 1 s, = 1 s,: 1 s 6) If you want to display the line number of the text on the left, you can use the following statement: Set nu 7) Finally, add the following statement if & term = "xterm" set t_co = 8 set t_sb = ^ [[4% dmset t_sf = ^ [3% dmendif
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.