Vim:搜索模式并将文本添加到每行发生的末尾

Dav*_*son 6 vim search replace

我想在vim中搜索一个模式,并在它出现的每一行上,将文本添加到行的末尾.例如,如果搜索模式是print(,则要添加的文本是):

from __future__ import print_function
print('Pausing 30 seconds...'
print("That's not a valid year!"
Run Code Online (Sandbox Code Playgroud)

应该成为

from __future import print_function
print('Pausing 30 seconds...')
print("That's not a valid year!")
Run Code Online (Sandbox Code Playgroud)

Ken*_*ent 12

这个命令应该为你做:

:g/print(/norm! A)
Run Code Online (Sandbox Code Playgroud)

它能做什么:

:g/print(/   "find all lines matching the regex
norm! A)     "do norm command, append a ")" at the end of the matched line.
Run Code Online (Sandbox Code Playgroud)

你可能想检查一下

:h :g
Run Code Online (Sandbox Code Playgroud)

详情.