VIM Basic Learning Global

Source: Internet
Author: User

The global command can be used to format the EX command on the matching line in the specified mode:

: [range]g[lobal]/{pattern}/[Cmd]range-is the execution range (if default, is%) Global- command keyword pattern- match content cmd -ex command operation (default is print)

This command also has two reverse commands.

global! Vglobal (v)

They mean, on a line that doesn't match the pattern, perform a cmd operation

When the global command is used, it includes two steps,

The first step is to get the pattern match that already has the tag, and if the value is the default, the row that currently owns the tag is used

The line that produces the tag has the search result, x selected medium

The second step is to execute the cmd command

Let's go into a simple demo to see the following section

123

Now we use global to delete all rows that contain name

Method 1.:global/name/D Method 2. 1) Execute the pattern tag line-/name2) execute global command-global//

Now let's put all the lines in this article that contain the name string into register a

Originally thought the above operation can complete our demand, however, you use

Reg A

It will be found that the result of the output is

: Global/name/y A.

Originally, the use of the global execution of CMD is performed, when we use the lowercase a call register, is the content of the overwrite register, when we use a (append) on it.

As follows

: global/name/y A

What do we do if we want to sort the next few lines?

The sort command in vim is sort so we can use the following method

Method One: The command line selects the five elements above and then uses the command line: sort on the line.

Method two: direct command line: 32,36 sort on the line.

The above is only one place to sort, very simple. If you now have the following content

a<rofwjejfaeeufsroqfjljfaqw[pegjwpirgusjf/>a<AEEUFSROQFJLJFAROFWJEJFWPIRGUSJF 
a<rofwjejfaeeufsroqfjljfaqw[pegjwpirgusjf/>a<AEEUFSROQFJLJFAROFWJEJFWPIRGUSJF 

We can use the following command

: g/</+1,/\/>/-1sort


It means that the sort operation is performed from the/</+1 start to/\/>/-1 match
It's actually

: Extended form of [Range]g[lobal]/{pattern}/[cmd]

: g/{star}/,/{end}/cmd


This feeling is consistent with the previous form, which is to give the cmd a clear scope for execution.
: G Position Range Command

VIM Basic Learning Global

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.