VIM:在所有选定的行中播放宏观失败



我有一个类似的文本:

var a = [
  {"id": 1, "name": "Name 1", "description": "Description for item #1"},
  {"id": 2, "name": "Name 2", "description": "Description for item #2"},
  {"id": 4, "name": "Name 4", "description": "Description for item #4"},
  {"id": 5, "name": "Name 5", "description": "Description for item #5"},
  {"id": 6, "name": "Name 6", "description": "Description for item #6"},
  {"id": 7, "name": "Name 7", "description": "Description for item #7"},
  {"id": 8, "name": "Name 8", "description": "Description for item #8"},
  {"id": 9, "name": "Name 9", "description": "Description for item #9"},
  {"id": 10, "name": "Name 10", "description": "Description for item #10"},
  {"id": 11, "name": "Name 11", "description": "Description for item #11"},
  {"id": 12, "name": "Name 12", "description": "Description for item #12"},
  {"id": 13, "name": "Name 13", "description": "Description for item #13"},
  {"id": 14, "name": "Name 14", "description": "Description for item #14"},
  {"id": 15, "name": "Name 15", "description": "Description for item #15"},
]

我想在列表的所有对象成员中添加"姓氏"项目,它们应该成为这样的东西:

var a = [
  {"id": 1, "name": "Name 1", "lastName": "Last Name 1", "description": "Description for item #1"},
  {"id": 2, "name": "Name 2", "lastName": "Last Name 2", "description": "Description for item #2"},
  {"id": 4, "name": "Name 4", "lastName": "Last Name 4", "description": "Description for item #4"},
  {"id": 5, "name": "Name 5", "lastName": "Last Name 5", "description": "Description for item #5"},
  {"id": 6, "name": "Name 6", "lastName": "Last Name 6", "description": "Description for item #6"},
  {"id": 7, "name": "Name 7", "lastName": "Last Name 7", "description": "Description for item #7"},
  {"id": 8, "name": "Name 8", "lastName": "Last Name 8", "description": "Description for item #8"},
  {"id": 9, "name": "Name 9", "lastName": "Last Name 9", "description": "Description for item #9"},
  {"id": 10, "name": "Name 10", "lastName": "Last Name 10", "description": "Description for item #10"},
  {"id": 11, "name": "Name 11", "lastName": "Last Name 11", "description": "Description for item #11"},
  {"id": 12, "name": "Name 12", "lastName": "Last Name 12", "description": "Description for item #12"},
  {"id": 13, "name": "Name 13", "lastName": "Last Name 13", "description": "Description for item #13"},
  {"id": 14, "name": "Name 14", "lastName": "Last Name 14", "description": "Description for item #14"},
  {"id": 15, "name": "Name 15", "lastName": "Last Name 15", "description": "Description for item #15"},
]

我的宏是这个

:reg l
--- Registers ---
"l   0f:2lyiw2f,a "lastName": "Last Name 0",^[2hmi2F,hyiw`iviw"0p

并且在一行中正常工作,或者如果我附加j以在末端移动并像14@l一样运行,则可以正常工作。

我无法完成的工作是通过V,然后键入:normal @l的所有行,因为它只能在选定的第一行(无论是j还是在末尾都没有附加(。如何使其在所有选定的行中工作?

您需要做,一旦选择了行:

:'<,'>norm @l

在所有选定的行中执行。:normal @l仅在当前行上执行。

另外,您可以直接提供一系列线(而不是以视觉模式进行(:

:10,20norm @l

其中1020是您要覆盖的范围的第一行和最后一行。

作为额外

:g/"name"/norm @l

在匹配"name"

的所有行上执行宏

相关内容

  • 没有找到相关文章

最新更新