Vim Text Editing Tool-Modify file contents

Source: Internet
Author: User

To replace text in VIM:

1. Replace the from in the current line: s/from/to/(where S is the first letter of the English word substitute the meaning of the substitution)

: s/from/to/= =:. s/from/to/, add one before S. (dot) default does not write, indicating when the forward

Note::s/from/to/replaces the first from, in the current row, with a to. If the current row contains more than one from, only the first from is replaced. If you want to replace all occurrences of the from in the current line

You can add "g" to write this s/from/to/g.

2. Replace all from in the current line with a query: S/FROM/TO/GC

3. Replace the contents of a line: s/from/to/g (replace nth row, n indicates the nth row of the file, n is the line number)

: 33s/from/to/g replaces the 33rd line with all from

4. Replace the contents of some lines: n1,n2s/from/to/g (replace N1 to N2)

: 1,33s/from/to/g replace 1 lines to 33 rows

5. Replace the contents of the full text from:%s/from/to/g = =: 1, $s/from/to/g

Commonly used to represent ranges range, do not write range: The default is the line of the cursor

. Indicates that the cursor is in the row

1 First line

$ last line

33 Line 33rd

The line of ' a ' marked a: ' A, ' bs/from/to/replaces the line between Mark A and Mark B

. +1 the line below which the current cursor is located

$-1 the penultimate line (this shows that we can add a value to a row to get a relative line)

22,33 Line 22nd to 33rd

1,. The first line moves forward

., $ current line to last row

' A, ' B marks the line where a is located to the row where Mark B is located

% all rows = = 1,$ (denotes all rows)

6. Continuous comment File Multi-line method:
Under the VIM editor

Enter command mode by colon

:%s/^/#/Comment All rows
: 1, $s/^/#/note all rows are equivalent here to replace

Tips:

: n1,n2/^/#/continuous Comment N1 to N2 line.
Cancel Comment
:%s/^#//Uncomment All lines
: n1,n2/^#//uncomment N1 to N2 line

(2) The second method of Chinese law

Under Vim

CTRL + V enters visualization mode
Move the cursor up or down, select the beginning of multiple lines
When you are finished, press the I key in the upper case, and you will be prompted to enter the "Insert" mode below, entering the annotation you want to insert, such as #,

Press ESC at the end and you'll notice that multiple lines of code have been commented

Vim Text Editing Tool-Modify file contents

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.