[Practical.Vim(2012.9)].Drew.Neil.Tip28 學習摘要

來源:互聯網
上載者:User

標籤:vim

Tip28

Use Line Numbers as an Address
If we enter an Ex command consisting only of a number, then Vim will interpret that as an address and move our cursor to the 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:
除了通過行數來指定文本地區,我們可以先做一個visual selection.如果我們依次運行命令2G,VG,我們就會得到這樣一個visual selection

If we press the : key now, the command-line prompt will be prepopulated with the range :’<,’>. It looks cryptic, but you can think of it simply as a range standing for the visual selection. Then we can specify our Ex command, and it will execute on every selected line:
如果這時我們輸入: ,命令提示會彈出範圍 :’<,’> 。這個看起來很奇怪,但是你可以把這個當作一個visual selection的選擇範圍。然後我們可以輸入Ex命令,然後就會在每一行上執行。

The ‘< symbol is a mark standing for the first line of the visual selection, while ‘> stands for the last line of the visual selection.
‘<表示visual selection的第一行,’>表示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在Ex命令中還可以把pattern作為address,例如下面

the range begins on the line containing an opening <html>tag and ends on the line containing the corresponding closing tag.
這個範圍開始於包含<html>標籤的行,結束於包含對應關閉標籤的行。

Modify an Address Using an Offset
Suppose that we wanted to run an Ex command on every line inside the<html></html>block but not on the lines that contain the<html> and</html> tags themselves. We could do so using an offset:
假設我們打算在<html></html> 範圍內的每一行執行Ex命令,但是並不包含<html></html> 所在行,我們可以用offset來實現。

The general form for an offset goes like this:
offset的一般使用方法如下:

:{address}+n

If n is omitted, it defaults to 1. The {address} could be a line number, a mark, or a pattern.
如果沒有n,預設值為1. address可以為行數,mark,或pattern.

Suppose that we wanted to execute a command on a particular number of lines, starting with the current line. We could use an offset relative to the current line:
假設我們打算在特定的行上執行命令,從當前行開始,我們可以利用offset這樣做。

:.,.+3p

The . symbol stands for the current line, so :.,.+3 is equivalent to :2,5 in this case.
. 表示當前行,所以 :.,.+3 在這個例子中表示:2,5

Line 0 doesn ’t really exist, but it can be useful as an address in certain contexts. In particular, it can be used as the final argument in the :copy {address} and :move {address} commands when we want to copy or move a range of lines to the top of a file
0行並不存在,不過在特定上下文中非常有用。特別是當我們項複製或移動一段代碼到檔案的頭部的時候,它可以作為:copy {address}:move {address} 命令的最終參數。

[Practical.Vim(2012.9)].Drew.Neil.Tip28 學習摘要

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.