使用搜索和替换将内容移到大括号命令之外 (Vim)
我有这样的命令:
\bold{Foo Bar}
\bold{Foo Bars}
\bold{Foos Bar}
....
\bold{Zoo Cars}
并且我想将它们变成
Foo Bar
Foo Bars
Foos Bar
...
Zoo Cars
:%s/\bold{*}//gc
甚至找不到任何匹配项。我该怎么做?
注意:我到处搜索,但没有任何搜索有帮助。
I have commands like this:
\bold{Foo Bar}
\bold{Foo Bars}
\bold{Foos Bar}
....
\bold{Zoo Cars}
and I want to turn them into
Foo Bar
Foo Bars
Foos Bar
...
Zoo Cars
:%s/\bold{*}//gc
does not even find any matches. How do I do this?
Note: I googled all around but none of the searches helped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更改分隔符搜索,用逗号交换栏。轻松查看
change the delimiter searches, swapping bar by comma. Easy view
您正在编写一个正则表达式,但您认为它是一个全局变量。您也根本不提供替代品。尝试
:%s/\\bold{\(.*\)}/\1/gc
。You're writing a regexp, but you think it's a glob. You're also not providing a replacement at all. Try
:%s/\\bold{\(.*\)}/\1/gc
.你可以用两种方法(至少)
(你需要转义粗体前面的“\”字符)
我的建议,分两次完成
如果你想一次性完成
<前><代码>%s/\\粗体{\(.*\)}/\1/
另外,你真的需要最后的“gc”吗?根据您的样本数据并非如此。
我希望这有帮助。
you can do it 2 ways (at least)
(you need to escape the '\' char in front of bold)
my recommendation, do it in 2 passes
if you want to do it all at once
Also, do you really need the 'gc' at the end? Not so based on your sample data.
I hope this helps.
我知道已经有很多答案,但我真的不喜欢与 VIM 的替换作斗争,我总是使用
global
和normal
命令来执行以下任务:<代码>
:g/^\\粗体/正常 df{f}x
g/^\\bold/ 选择以
\bold
开头的行,normal
告诉 VIM 运行以下命令普通模式下的指令:df{f}x
。这意味着:df{
= 删除,直到找到 {;f}
= 将光标移动到下一个};x
= 删除光标下的 };I know that there are already a lot of answers, but I really don't like to struggle with VIM's substitutions, I always use the
global
andnormal
command for tasks this::g/^\\bold/normal df{f}x
The
g/^\\bold/
selects the lines that starts with\bold
and thenormal
tells VIM to run the following instructions in the normal mode:df{f}x
. Which means:df{
= Delete until you find an {;f}
= Mode the cursor to the next };x
= Removes the } under the cursor;