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

Source: Internet
Author: User
Tags closing tag

Tip28

Use Line Numbers as an Address
If we enter an Ex command consisting only of a number, then Vim would interpret that as an address and move our cursor to T He specified line.

Specify a Range of Lines by Visual Selection
Instead of addressing a range of lines by number, we could just make a visual selection. If we ran the command 2G followed by VG, we would make a visual selection that looks like this:
In addition to specifying the text area by the number of rows, we can first make a visual selection. If we run command 2G,VG in turn, we'll get a visual selection

If We press The:key now, the command-line prompt would be a prepopulated with the range: ' < It looks cryptic, but can think of it simply as a range standing for the visual selection. Then we can specify our Ex command, and it'll execute on every selected line:
If at this point we enter:, the command prompt will pop up range: ' <, ' >. This looks strange, but you can think of this as a visual selection choice. Then we can enter the EX command and then execute it on each line.

The ' < symbol is a mark standing for the first line of the visual selection, while ' > stands for the last line of th e visual Selection.
' < represents the first line of visual selection, ' > represents the last line of visual selection.

Specify a Range of Lines by Patterns
Vim also accepts a pattern as an address for an Ex command, such as the one shown here:
Vim can also use pattern as an address in the ex command, such as the following

The range begins on the line containing a opening tag and ends on the line containing the corresponding closing tag.
This range begins with the row containing the label and ends with the row containing the corresponding closing label.

Modify an Address Using an Offset
Suppose that we wanted to run a Ex command on every line inside the block and not on the lines that contain the and tags themselves. We could the using an offset:
Suppose we intend to execute the ex command in each row within the range, but not the line and the row, we can do it with offset.

The general form for a offset goes like this:
The general way to use offset is as follows:

:{address}+n

If n is the omitted, it defaults to 1. The {address} could is a line number, a mark, or a pattern.
If n is not, the default value is 1. Address can be a line number, mark, or pattern.

Suppose that we wanted to execute a command on a particular number of lines, starting with the current line. We could use a offset relative to the current line:
Suppose we intend to execute a command on a particular line, starting with the current line, we can do this using offset.

:.,.+3p

The. Symbol stands for the current line, so:.,. +3 are equivalent to:2,5 in this case.
. Represents the current row, so :.,.+3 in this example :2,5

Line 0 doesn ' t really exist, but it can be useful as a address in certain contexts. In particular, it can is used as the final argument in the:copy {address} and:move {Address} commands if we want to co PY or move a range of lines to the top of a file
0 rows do not exist, but are useful in a specific context. In particular, when we copy or move a piece of code to the head of a file, it can be used as :copy {address} :move {address} the final parameter of the command.

[Practical.vim (2012.9)]. DREW.NEIL.TIP28 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.