Vim's last-line mode explanation

Source: Internet
Author: User

Last-line mode focuses on (this is the basis for learning the SED)
1) Address delimitation
: Start_pos[,end_pos]
#: Specific # lines, e.g. 5 for line fifth
.: When moving forward
$: Last line
#,#: Specifies the row range, the left is the start row
#,#+: Specifies the line range and the right side is the offset of the left row, for example: 3,+7
%: Full text
/pattern/: The first row to be matched by the pattern

2: Edit operation can be realized, with edit command together with
D: For direct deletion, the requirement is directly following the address delimitation symbol, for example:., $d represents the current row to the last row to delete.
Y: Used to copy the line to which the address is bound to match
C: Used to modify the line to which the address is bound to match
W/path/to/file: Save the text in the range to a file
R/path/to/file: Inserts the text of the specified file into the specified location

3: Find
/pattern: Find pattern matches all strings to, look down, and then press N on the keyboard to continue to match down
? Pattern: Finds all the strings that the pattern matches to, looks up, and then presses the N key on the keyboard to continue to match up

Find and replace (extremely important)
(1) Format:Address delimiter s/What to look for/replace with content/modifiers
What to look for: You can use regular expressions
What to replace: You cannot use regular expressions, but you can reference
If you use a grouping, that is, use the () in the content you are looking for, you can use a back reference, \1 to refer to the first parenthesis match, \2 to indicate the second parenthesis match, \3 to indicate that the third parenthesis matches the entire text that the lookup pattern matches. Use the full text of the matching pattern directly:use the & symbol to refer to text that matches the entire pattern

(2) modifier
I: Ignore case
G: Global substitution, that is, if you do not add g, then it is only one line match, if the second is matched and will not be replaced, if you add g, then no matter how many matches in a row will be replaced

(3) can replace the delimiter with non-commonly used characters
For example: [Email protected]@@
s###

Practice
1. Copy the/etc/grub2.cfg file to the/tmp directory, and use the Find replacement command to delete the white space character at the beginning of the line beginning with a blank character in the/tmp/grub2.cfg file
:%s#^[[:space:]]\+# #g\+: Matches its preceding character one or more times, that is, the character before it appears at least once%: Full text

2: Copy the/etc/rc.d/init.d/functions file to the/tmp directory, and use the Find replacement command to add # to the first line of the line beginning with each white-space character of the/tmp/functions file
%s#^[[:space:]]#\#&#g

3. Add # to the beginning of the first three lines of the/tmp/grub2.cfg file
1,3s#^.#\#&#.: The current line 1,3 address delimitation 1,3s/^/\#/can also
4. Replace all enabled=0 in the/etc/yum.repos.d/centos-base.repo file with ennabled=1, all gpgcheck=0 replaced by gpgcheck=1
%s#\ (enabled\|gpgcheck\) =0#\1=1#g

This article is from the "11018816" blog, please be sure to keep this source http://11028816.blog.51cto.com/11018816/1955985

Vim's last-line mode explanation

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.