如何禁用 vim 的 switch case 缩进?

发布于 2024-09-13 18:50:49 字数 515 浏览 9 评论 0原文

我目前正在与 Vim 作斗争,我似乎无法让缩进选项达到我想要的效果。

这是我的设置,我将它们放在 .vimrc 的底部以确保它们优先。正如你所看到的,我有点疯狂,所以我尝试关闭几乎所有内容:

set cindent
set cinkeys=o,O
set cinoptions=
set cinwords=
set indentexpr=

在大多数情况下,它似乎工作正常,它在打开一个块后进行一次缩进,一切都很好。但有一种情况让我发疯,当 case 语句后面有一个 { 时,下一行缩进得太远:

switch () {
    case CASE: {
                   // <-- next line gets indented to here, why??
        // <-- should be indented to here

我怎样才能让它停止做这个? TIA

I'm currently fighting with Vim, I can't seem to make the indentation options do what I want.

Here are my settings, I put them at the bottom of .vimrc to make sure they take precedence. As you can see I'm going a little crazy, so I tried turning off almost everything:

set cindent
set cinkeys=o,O
set cinoptions=
set cinwords=
set indentexpr=

In most cases it seems to work fine, it does one indent after opening a block and everything is fine. But there is one case that is driving me crazy, when there is a { after a case statement, the next line is way too far indented:

switch () {
    case CASE: {
                   // <-- next line gets indented to here, why??
        // <-- should be indented to here

How can I make it stop doing this? TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

美煞众生 2024-09-20 18:50:49
:set cinoptions=l1

(即字母 ell 后跟数字一)

查看 :help cinoptions-values 了解默认字符串和不同选项的描述。

:set cinoptions=l1

(that's the letter ell followed by a number one)

Look at :help cinoptions-values for the default string and descriptions of the different options.

君勿笑 2024-09-20 18:50:49

如果缩进为 N 个空格(将 N 替换为实际值),请尝试以下操作

set cinoptions=p0,t0,:N,=0
set cinwords=if,else,switch,case,for,while,do
set cindent

:N ->将 'case' 标签放置在距 switch 缩进 0 个字符处

=0 ->;缩进 case 标签内的语句

If indent is N spaces (replace N with actual value), try the following

set cinoptions=p0,t0,:N,=0
set cinwords=if,else,switch,case,for,while,do
set cindent

:N -> place 'case' label 0 characters from switch's indent

=0 -> indents the statements within case label

惯饮孤独 2024-09-20 18:50:49

当我手动键入 set 命令时,我没有任何缩进。您是否查看过 :set all 的输出来确认您的设置没有被覆盖?

注意:这可能应该在评论中,但目前我不允许该选项。

When I manually key in your set commands, I get no indentation whatsoever. Have you looked at the output of :set all to confirm your settings are not being overridden?

Note: This should probably be in a comment, but that option is presently disallowed to me.

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