"Linux" Vim indent configuration (reprint)

Source: Internet
Author: User

1. Install VIM, terminal input:

[Email protected]:~$ sudo apt-get install Vim-full


2. Terminal input, open the configuration file:

[Email protected]:~$ vim ~/.VIMRC


3. Overwrite the configuration file, Esc+:wq save exit:

2:set softtabstop=4

3:set shiftwidth=4

4:set Autoindent

6:set nu

7:set hlsearch

8:set backspace=2


4.
1. Set Tab width
: Set tabstop=4
: Set softtabstop=4
2. Set the number of spaces in indent
: Set shiftwidth=4
3. The indent value of each row is equal to the previous line
: Set Autoindent
4. automatic indentation using the C + + language
: Set Cindent
5. Display line Numbers
: Set Nu
6. Turn search content back to White
: Set Hlsearch
7. You can delete any value
: Set backspace=2

5.ps: Novice ing ...

http://blog.chinaunix.net/u3/113943/showart.php?id=2221390

VI Command attached

First, VI basic commands

1) Cursor command
Left H Upper J Lower K right L
Ng--n is the number of rows, the command immediately causes the cursor to jump to the specified line, n is empty, and the cursor jumps to the last line of the file.
ctrl+g--the number of rows and columns at the cursor location report
w,b--causes the cursor to skip forward or backward through a word

2) Edit command
(n) DD Delete
(n) YY copy
I insert before cursor
A current letter inserted after
R is replaced at the current cursor
The word at which the CW replaces the cursor (starting at the beginning of the cursor)
DW Delete Word at cursor location
x Delete (right)
X Delete (left)
U undo
. Repeat Last Action
o Insert a new row
J Merge two lines
End of A Line
:., 3w/tmp/xx
: r/tmp/xx

3) Find command
F Find
/Find

4) Copy and Paste command
(n) yy copy n line to clipboard
P Paste (rear)
P Paste (current)

Second, vi option settings

VI is a powerful editor, it can not only be used to deal with our usual text work, but also can be used to write program files. When using VI for program editing, it can achieve syntax highlighting, automatic indentation, bracket matching and other editing functions. To control different editing functions, VI offers many internal options.

Use the: Set command to set options. The basic syntax is:
: Set option Settings options
Common feature options include the following:
Autoindent Set this option, the body is automatically indented
ignorecase Set this option, the difference between uppercase and lowercase letters in the rule expression is ignored
Number sets this option to display the body line numbers
Ruler Set this option, the location of the row and column of the cursor is displayed at the bottom of the screen
TabStop sets the number of spaces to skip by pressing the Tab key. Example: Set tabstop=n,n default value is 8

1) syntax highlighting
: syntax on the command to open the syntax highlighting feature in VI. In this way, VI will automatically recognize keywords, strings, and other grammatical elements in the input characters, and display them in different colors.

2) Auto Indent
The options for automatic indentation in VI are generally as follows:
Autoindent: In this form of indentation, the newly added row and the previous line have the same indentation form.

Smartindent: In this indentation mode, each row has the same indentation as the previous line, and it is correctly recognized that when the right curly brace (}) is encountered, the indent form is canceled. In addition, the ability to identify C keyword is added. If a line starts with #, this format will be treated in a special way instead of indented format. This indentation format is stronger than Autoindent.

Cindent: This is the C language indentation form, the use of such indentation in the language of the program is: C,c++,java and so on. When this indentation format is used, VI will automatically adopt the standard C language form. This indentation format is stronger than Smartindent.

You can use the following command to indent the settings:

: Set Autoindent (AI)
: Set Smartindent (SI)
: Set Cindent (CI)

3) Display line number
: Set Number (NU) Displays line numbers
: Set Nonumber (Nonu) does not display line numbers
In each user's directory, there is a VI configuration file ". VIMRC" (no words can be created by yourself). The user can edit it and enter the above command to make these settings valid for each VI. For example, add the following setting line to the. vimrc file:
Set Nu #显示行号
Set Nonu #不显示行号
Set IC #查找时不考虑大小写
Set Noic #查找时考虑大小写
Set Smartindent #自动缩进
Syntax on # syntax highlighting

GG moves the cursor to the first column in the first row of the file
V Toggle mode for Visual mode
G means move the cursor to the end of the file
This is the equivalent of selecting all the file contents,
= Enable Automatic typesetting

And gg=g is the same effect, but I am used to ...

"Linux" Vim indent configuration (reprint)

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.