GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — note/note/vim/26.md at master · trialbox/note

Expand file tree

/

26.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
24 lines (17 loc) · 1.44 KB
/

26.md

Copy path

File metadata and controls

24 lines (17 loc) · 1.44 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

每日一Vim(26)---跨行执行〈Normal模式下的〉命令

以往,要想在多行执行normal 模式下命令可以通过定义宏来重复操作,今天讲个新鲜的。:normal命令。之前讲过一个列子,实现注释多行代码这样一个需求,可选的方法如下三种方式:(当然你还可以相出更多的办法来)

import urllib2
def html():
    f = urllib2.urlopen("http://www.douban.com")
    print f.read()
  1. 替换::%s/^/#/g
  2. visual block:gg<Ctrl-v>I#<Esc>
  3. 注释第一行后用.重复执行每一行

我们可以在第三种方法之上用normal命令实现上述需求,步骤:

  1. 光标定位到首行,执行:I#<Esc>
  2. jVG选中之后的所有行
  3. :'<,'>normal .这样刚刚选中的行都将执行.代表的最后一次操作。注:只要输入:就能实现:'<,'>,你可以注意VIm的左下角的提示。

第四种方法::%normal I#,%代表这个文件,当然你可以选择具体的范围,如::1,4normal I#

总结::normal命令可以执行任何normal 模式下的命令,更多帮助::help normal。对了,上面这个例子你还可以用“宏,record”来达到要求,如果没有想起来,翻开Recode/Play试试吧。

转载请注明出处,谢谢合作!作者---zhijun

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.