Vim 全局命令使每一行包含一个符号,以单词开头
考虑以下文本文件:
something
something
something = someother thing
other thing = third thing
another thing = forth thing
我想让它看起来像这样:
something
something
keyword something = someother thing
keyword other thing = third thing
keyword another thing = forth thing
这样,我向每一行添加关键字,其中包含一个等号。 我可以使用全局命令来执行此操作吗?或者您建议我应该如何执行此操作?
Consider following text file:
something
something
something = someother thing
other thing = third thing
another thing = forth thing
I want to make it look like this:
something
something
keyword something = someother thing
keyword other thing = third thing
keyword another thing = forth thing
so that, I add keyword to each line, what is contains a equals symbol in it.
Can I do this with global command, or how do you recommend I should do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或
注意“关键字”后面的空格
对于此类问题,使用如下解决方案也很常见:
or
Note the space after "keyword"
For this type of problem, it's also quite common to use a solution like:
我不太确定你想要实现什么目标。您的标题暗示了一种常见模式,但我在您的示例中没有看到这种模式。所以我会向你们展示两者。
使用通用模式对事物进行更改
您可以使用以下内容进行搜索和替换:
s/pattern/replacement/
进行搜索和替换替换,额外的 g 将传播更改多行编辑
Vim 还允许您一次编辑多行。假设您要编辑以下三行:
something
的s
上。在插入模式之外按
-v
进入可视模式。`a
。所有 3 行的所有三个起始字符都应突出显示。A
追加或按I
直接进入插入模式并开始输入。当您点击退出时,您的更改应该会反映出来!您还可以执行其他命令,例如y
和d
等。I'm not quite sure what you're attempting to accomplish. Your title suggests a common pattern, but I don't see one in your example. So I'll show you both.
Making Changes Among Things With A Common Pattern
You can do search and replace with the following:
s/pattern/replacement/
does search & replace, and the extra g will propogate the changesMulti-Line Edit
Vim also lets you edit multiple lines at once. Say you want to edit the following three lines:
s
at the firstsomething
line.Press
<ctrl>-v
outside of insert mode to go into Visual mode.`a
on the bottom line. All three starting characters of all 3 lines should be highlighted.A
to append orI
to enter directly into insert mode and start typing. When you hit escape your changes should reflect! You can also do other commands likey
andd
, etc.