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

來源:互聯網
上載者:User

標籤:global   vim   

Meet The Global Command

The :global command allows us to run an Ex command on each line that matches a particular pattern. Let’s start by studying its syntax. The :global command takes the following form (see :h :g ):
:global命令可以讓我們在每一行匹配特定pattern的文本上執行Ex命令。我們首先學習它的文法。:global命令形式如下

:[range] global[!] /{pattern}/ [cmd]

The default range for the :global command is the entire file (%). That sets it apart from most other Ex commands, including :delete, :substitute, and :normal, whose range is the current line (.) by default.
:global命令的預設range為(%) 也就是全文範圍,和其他的Ex命令如:delete,:substitude,:normal的預設range不一樣,這些命令的預設range為(.)當前行。
The {pattern} field integrates with search history. That means we can leave it blank and Vim will automatically use the current search pattern.
{pattern}可以和搜尋曆史整合。意味著我們可以把這一項留空,然後Vim會自動用當前的搜尋pattern.
The [cmd] could be any Ex command except for another :global command
[cmd]可以是除了:global命令的任何的Ex命令。

We can invert the behavior of the :global command either by running :global! or :vglobal (mnemonic: invert). Each of these tells Vim to execute [cmd] on each line that doesn’t match the specified pattern.
我們可以反轉:global的效果通過使用:global!:vglobal.這些符號告訴Vim在每一條不匹配pattern的行上執行命令[cmd]

The :global command works by making two passes through the lines specified by [range]. In the first pass, Vim marks each line that matches the specified {pattern}. Then on the second pass, the [cmd] is executed for each marked line. The [cmd] can accept a range of its own, which allows us to operate on multiline regions.
:global命令執行時,由[range]指定的行將會被傳遞兩次。在第一次傳遞時,Vim標註那些匹配{pattern}的行,然後在第二次傳遞時,這些被標記的行執行[cmd]命令。[cmd]命令可以接受range本身,允許我們在多個行上執行命令。

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.