程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> [Practical.Vim(2012.9)].Drew.Neil.Tip28 學習摘要

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

編輯:關於C++

Tip28

測試用例

Use Line Numbers as an Address<喎?/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjxiciAvPg0KSWYgd2UgZW50ZXIgYW4gRXggY29tbWFuZCBjb25zaXN0aW5nIG9ubHkgb2YgYSBudW1iZXIsIHRoZW4gVmltIHdpbGwgaW50ZXJwcmV0IHRoYXQgYXMgYW4gYWRkcmVzcyBhbmQgbW92ZSBvdXIgY3Vyc29yIHRvIHRoZSBzcGVjaWZpZWQgbGluZS48L3A+DQo8cD48c3Ryb25nPlNwZWNpZnkgYSBSYW5nZSBvZiBMaW5lcyBieSBWaXN1YWwgU2VsZWN0aW9uPC9zdHJvbmc+PGJyIC8+DQpJbnN0ZWFkIG9mIGFkZHJlc3NpbmcgYSByYW5nZSBvZiBsaW5lcyBieSBudW1iZXIsIHdlIGNvdWxkIGp1c3QgbWFrZSBhIHZpc3VhbCBzZWxlY3Rpb24uIElmIHdlIHJhbiB0aGUgY29tbWFuZCAyRyBmb2xsb3dlZCBieSBWRywgd2Ugd291bGQgbWFrZSBhIHZpc3VhbCBzZWxlY3Rpb24gdGhhdCBsb29rcyBsaWtlIHRoaXM6PGJyIC8+DQqz/cHLzai5/dDQyv3AtNa4tqjOxLG+x/jT8qOsztLDx7/J0tTPyNf20ru49nZpc3VhbCBzZWxlY3Rpb24uyOe5+87Sw8fSwLTO1MvQ0MP8we4yR6OsVkejrM7Sw8e+zbvhtcO1vdXi0fnSu7j2dmlzdWFsIHNlbGVjdGlvbjxiciAvPg0KPGltZyBhbHQ9"這裡寫圖片描述" src="/uploadfile/Collfiles/20150413/2015041308393596.jpg" title="\" />

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

tag and ends on the line containing the corresponding closing tag.
這個范圍開始於包含標簽的行,結束於包含對應關閉標簽的行。

Modify an Address Using an Offset
Suppose that we wanted to run an Ex command on every line inside the

block but not on the lines that contain theand tags themselves. We could do so using an offset:
假設我們打算在范圍內的每一行執行Ex命令,但是並不包含和 所在行,我們可以用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} 命令的最終參數。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved