How to disable vim's indentation of switch case?

爷,独闯天下 提交于 2019-12-03 15:08:19

问题


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


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3444696/how-to-disable-vims-indentation-of-switch-case

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!