[Practical.vim (2012.9)]. DREW.NEIL.TIP100 Study Summary

Source: Internet
Author: User

Alphabetize the Properties of each Rule in a CSS File

When combining a Ex command With:global, we can also specify a range for our chosen [cmd]. Vim allows us to set the range dynamically using The:g/{pattern} as a reference point.
When used with: global combined with the EX command, we can specify the text area for command [CMD]. Vim allows us to make use of :g/{pattern} dynamic settings areas.

Sort Properties for a single Block of Rules

We're going to sort the text in {} by the first letter, and we can do that by manually selecting the area and then executing the sort command

But what if there are so many {} areas in the file that need to be sorted?

Sort Properties for every Block of Rules

We can execute the following command:
:g/{/ .+1,/}/-1 sort
This command is very complex, but understanding will help us understand how powerful the global command is. We already know the standard form for
:g/{pattern}/[cmd]
We also know that the ex command can accept an area range. This is also used in the: Global command. So we can extend the above command.
:g/{pattern}/[range][cmd]

The range can be set using the matching result of: G/{pattern} as a reference point. Usually symbols. Represents the address at which the cursor is located. In: Global represents each row that matches {pattern}.

We have divided the order into two separate ex commands to see. First, let's see
:.+1,/}/-1 sort
If we remove the offsets, we get .,/}/ . This command can be translated into rows from the current line to the next matching/}/ . The +1-1 offset narrows the scope to what {} contains.
Now all we have to do is place the cursor over { and then execute it to :.+1,/}/-1 sort sort the contents of {}. Find { You can use
/{/
Now that you have two commands together, you can get a
:g/{/ .+1,/}/-1 sort

Discussion

: The general form of the global command is
:g/{start}/ .,{finish} [cmd]
We can translate to, for the area starting at start, ending to {finish}, execute command [cmd]

[Practical.vim (2012.9)]. DREW.NEIL.TIP100 Study Summary

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.