VI Multi-line indentation Tips

Source: Internet
Author: User
1. Enter the visual state by V, select multiple lines and indent or indent with > or <

2. Automatic indent typesetting is usually used according to language features: in the command state = = Two for the current line, or for multiple rows with n== (n is the natural number) for automatic indentation from the current line below n rows. You can try to indent code arbitrarily and then use n== typesetting, equivalent to the General IDE in the code format. Use GG=G to format the entire piece of code.
3.gg shift+g 4. Full text replaces%s/source/dist/g or: 1,$ s/source/dist/g: s/vivian/sky/replaces the current line the first Vivian for Sky

: S/vivian/sky/g replaces current line all Vivian for Sky

: N, $s/vivian/sky/replaces the first n line to the top Vivian for each line in the last line of Sky

: N, $s/vivian/sky/g replaces the first n line to each line in the last line all Vivian for Sky

N is a number, and if N is., it means starting from the current line to the last line

:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky

:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky

You can use # as a separator, in which the middle appears/is not a separator

: s#vivian/#sky/# Replace the first vivian/of the current line as sky/

:%s+/oradata/apras/+/user01/apras1+ (using + to replace/):/oradata/apras/replaced with/user01/apras1/

* ************************************

1.:s/vivian/sky/replaces current line first Vivian for Sky

: S/vivian/sky/g replaces current line all Vivian for Sky

2.: N, $s/vivian/sky/replaces the first n line to the top of each line in the last line Vivian for Sky

: N, $s/vivian/sky/g replaces the first n line to each line in the last line all Vivian for Sky

(n is a number, if N is., which means starting from the current line to the last line)

3.:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line for Sky

:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky

4. You can use # as a separator, which appears in the middle/not as a separator

: s#vivian/#sky/# Replace the first vivian/of the current line as sky/

5. Delete the ^m in the text

Problem Description: For newline, window with carriage return Line (0A0D) to express, Linux is a carriage return (0A) to express. This way, there will always be a ^m when you copy files on Windows to UNIX. Write a shell or C program that filters a line break (0D) for a window file under UNIX.

· Using commands: Cat filename1 | tr-d "^v^m" > NewFile;

· Use command: sed-e "s/^v^m//" filename > OutputFileName. It should be noted that in 1, 22 of the methods, ^v and ^m refer to Ctrl + V and ctrl+m. You have to enter it manually instead of pasting it.

· In VI Processing: First use VI to open the file, and then press the ESC key, and then enter the command:%s/^v^m//.

· :%s/^m$//g

If the above method is useless, the correct solution is:

· Tr-d "/R" < src >dest

· Tr-d "/015" dest

· Strings A>b

6. Other

Use the: s command to implement a string substitution. The specific uses include:

: s/str1/str2/replaces the first occurrence of a string with a string str2 str1

: S/str1/str2/g replaces all occurrences of the string in a line with a string str2 str1

:., $ s/str1/str2/g Replaces all occurrences of the body's current line to the end with a string str2 str1

: 1,$ s/str1/str2/g replaces all occurrences of a string in the body with a string str2 str1

: g/str1/s//str2/g function ditto

From the above substitution command you can see that G is placed at the end of the command to replace each occurrence of the search string;

The first occurrence of the string is substituted; G is placed at the beginning of the command to replace all the lines in the body that contain the search string.

[Essence] VI advanced Command collection


In view of the use of the VI when there is a certain strange, here Jiehuaxianfo, from the brother version of the [SHELL] sorted out the following on VI programming advanced skills, I hope to learn from Unix help, and hope that we can combine the experience of using HPUX to further expand these experiences.

1. Swap two character positions

Xp
2. The next two lines Exchange
Ddp
3. Reverse the contents of the document
: g/^/m0/(not passed)

4. Merge on the next two lines
J
5. Delete all rows
Dg
6. Delete from current position to end of line
d$
7. Copy from current position to end of line
y$ if you want to paste it into another place p is okay.


Since VI is based on EX, it comes to the ex command state when you type:
8.
: AB String strings
For example &quot;:ab USA United States of america&quot; ,
When you insert the USA in the text see
United States of America jumped out.
9.
: Map Keys New_seq
Define your current keyboard command
10.
: Set [All]
Edit Status of VI or EX
If each line is displayed: Set Nu
11.
In the command state, Nyy represents a copy of the following n-line content from the cursor line, p means paste, and the content that is just copied is pasted at the cursor at the
Below.

12.
A single character replaces with R, overrides multiple characters with R, replaces one character with multiple characters with S, whole line replaces with S

13.

:%s/old_word/new_word/g
This directive is to replace a specific string in the entire file

14. Cursor Control

K: Move up NK up N line
J: Move Down NJ down n row


Move the cursor to the nth line, and press Mk
Move the cursor to line M, press &quot;ay ' K
The rows N to M are to be saved to a register, and so on, b,c ... Registers, etc.

This will allow you to paste your favorite content into a different register to spare


Want to paste somewhere, directly to move the cursor to a place, press the ' AP can, and so on, b,c ... Registers, etc.

In the current screen
H jumps to the first line
M jumps to the middle row
L jump to the last line

15.
Table 8-2 Delete Commands
Delete command action
D l deletes the current character (same as the X command function)
D 0 Delete to the beginning of a line
d ^ Delete to the first character position of a line (excluding spaces or ta b characters)
D-W deletes to the end of a word
D 3 W Delete to the end of the third word
D b Delete to the beginning of a word
D W deletes to the end of a word that is delimited by a space
D B Delete to the beginning of a word with a space separator
D 7 B Delete to the beginning of the previous 7 words with a space separator
d) Delete to the end of a statement
D 4) Delete to end of fourth statement
D (deletes to the beginning of a statement
D} deletes to the end of a paragraph
d {Delete to the beginning of a paragraph
D 7 {Delete the 7th paragraph position before the beginning of the current paragraph
D d Delete When moving forward
d/t e x t deletes the position of the typeface specified in "T e x T" from the text until the next occurrence of the typeface
The content between the location (but not the typeface)
D FC deletes the position of the character "C" appearing from the text until the next occurrence of the character (including
The content between the characters)
D TC Delete the current line until the next character "C" appears between the contents of the
D Delete to the end of a line
D $ Delete to the end of a line
5 D D deletes 5 lines of content starting from the current line
D L Delete until the last line on the screen
D H Delete until the contents of the first line on the screen
D G Delete the content until the end of the work buffer
d 1 G Delete content until the work buffer begins

Modify Command action
C L change the current character
C W Modify to the end of a word
C 3 W modified to the end of the third word
C B Modify to the beginning of a word
C W modifies the end position of a word that is delimited by a space
C B modifies the start position of a word that is delimited by a space
C 7 B modifies the start position of the first 7 words with a space separator
C 0 Modify to the end of a line
c) Modify to the end of a statement
C 4) modified to the end of the fourth statement
C (Modify to the beginning of a statement
C} Modify to the end of a paragraph
c {Modify to the beginning of a paragraph
C 7 {Change to the 7th paragraph position before the beginning of the current paragraph
C TC Modify the current line until the next character C appears between the contents of the position
C Modify to the end of a line
C C Modify when moving forward
5 c C modifies 5 lines of content starting from the current line


. Repeat the last modification.


Table 8-4 Substitution command
Replace command action
s replaces the current character with one or more characters
S to replace the current line with one or more characters
5 S replaces 5 characters starting with the current character with one or more characters


VI Replacement Usage rules:
: g/s1/s/s2/s3/g
The first G represents the replacement of each row that includes S1, and the second G indicates that all S2 for each row including S1 are replaced with S3
s represents substitution, S2 is the string to be replaced, he can be the same as S1 (if the same words are replaced by//), S3 is the replacement string


16.

Fx
Move to the right to the X character
Fx
Move left to X character
Tx
Move to the right to the X character before
Tx
Move left to X character
(Note: Of the above four commands, where x is the character you type)
& #59;
Semicolon, use with F and T, repeat once
,
Comma, with F and T, repeat on the negative.


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.