纠正 VIM 中错误的标记折叠

发布于 2024-07-18 08:26:05 字数 439 浏览 4 评论 0原文

我错误地对我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪我终i 2024-07-25 08:26:05

您忘记转义括号,并且 POSIX 字符类仅在字符类 [[:alpha:]] 内有效:

:%s$/\({{{\d/\) /\(#[[:alpha:]]/\)$\2 \1$g

但是请注意,您的示例文本不包含任何斜杠 - 是这就是您的示例文本实际上是什么样的?

上面的正则表达式将其更改

/{{{8/ /#A/

为此

#A/ {{{8/

You forgot to escape the parentheses, and the POSIX character classes are only valid within a character class [[:alpha:]]:

:%s$/\({{{\d/\) /\(#[[:alpha:]]/\)$\2 \1$g

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

/{{{8/ /#A/

To this

#A/ {{{8/
那一片橙海, 2024-07-25 08:26:05

:%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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文