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