The order of words exchanged in Vim line and the column exchange of text data

Source: Internet
Author: User
Tags italic font

Requirements Description

1. If you change all Chinese names in English to "fan Jianqiang" to "Qiangjian fan"

2. Turn all the "Change World,change mind! "Replace" change mind, change world! ”

3. Swap the age column and ID column for the following sample data

Name Age ID slary
A 20 1 10
b 19 2 10
C 21 3 10
D 21 5 10
E 22 4 10
F 23 6 10
G 23 7 10
H 17 8 10
J 24 10 10
K 26 9 10

Command implementation

The most direct approach to 1, 2 needs is to replace the whole text; for Demand 3, you can use block selection, then cut, paste! But not what Ben Boven to elaborate. Here's another way to implement this:

Requirement 1 command

:%s/\ (fan\) \ (jian\) \ (qiang\)/\3\2 \1/

Requirement 2 Command

:%s/\ (world\), change \ (mind\)/\2, change \1/

Requirement 3 Command

:%s/\ ([1-9][0-9]\)  \ ([1-9].\)/\2  \1/


This is how \ (\) is used

The pattern contained therein will be stored, numbered from left to right, with a maximum of 9 stored in one row. Access them by numbered access! For example, the above requirements 2,world saved to the number 1,mind to the number 2; so \2, change \1 the world and mind, changed the world, and replaced! Demand 1 and Demand 3 the same!

Description: Because \ and (combined into the escape of the Web page Italic font.) Instead of showing, here each \ and (between the spaces, note that the space is not part of the command

The order of words exchanged in Vim line and the column exchange of text data

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.