纠正 VIM 中错误的标记折叠
我错误地对我的 .vimrc 进行了标记折叠:
{{{8 #CS
something..
}}}8
{{{9 #Math
...
}}}9
... many more!
我需要将格式切换为“#SOMETHING {{{NUMBER”,例如:
#CS {{{8
something..
}}}8
#Math {{{9
...
}}}9
... many more!
以下代码中有什么问题:
:%s$/({{{\d/) /(#[:alpha:]/)$\2 \1$g
[解决方案]
%s$\({{{\d\) \(#[[:alnum:]]*\)$\2 \1$g
I mistakenly did marker folding to my .vimrc:
{{{8 #CS
something..
}}}8
{{{9 #Math
...
}}}9
... many more!
I need to switch the format to "#SOMETHING {{{NUMBER" like:
#CS {{{8
something..
}}}8
#Math {{{9
...
}}}9
... many more!
What is wrong in the following code:
:%s$/({{{\d/) /(#[:alpha:]/)$\2 \1$g
[Solution]
%s$\({{{\d\) \(#[[:alnum:]]*\)$\2 \1$g
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您忘记转义括号,并且 POSIX 字符类仅在字符类
[[:alpha:]]
内有效:但是请注意,您的示例文本不包含任何斜杠 - 是这就是您的示例文本实际上是什么样的?
上面的正则表达式将其更改
为此
You forgot to escape the parentheses, and the POSIX character classes are only valid within a character class
[[:alpha:]]
:Note, however, that your example text doesn't contain any slashes - is this what your sample text is actually like?
The above regex changes this
To this
:%s/{{{\(\d\) \(.*\)/\2 {{{\1/g
它有效,但在你的正则表达式中我不明白为什么s 之后你得到了一个 $。
:%s/{{{\(\d\) \(.*\)/\2 {{{\1/g
it works, but in your regex I don't understand why do you got a $ after s.