Monday, May 27, 2024

Adapting swich-case indentation

Is there a way to bend Vim to my will in indenting C switch-case statements with local scopes delimited by braces.  Here's what I mean: (Vim 9.1 on MacOS (M2 chip and Intel x86-64) 
int main() {
    int n = 42;
    switch (n) {
        case 42: {
            int twice = 2*n;
        }        
    }
}

The above example illustrates what I want:.  But when I visual-select those lines and press =. I get this:
int main() {
    int n = 42;
    switch (n) {
        case 42: {
                     int twice = 2*n;
                 }
    }

The compiler insists on the braces because of that local int twice variable;   putting the opening brace of the case: on its own line helps, but then I have a deviation from my preferred style. 

Please note that this example is contrived to illustrate the problem, not an excerpt from  an actual program..

Am I just finally asking too much of Vim?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/e1c52cd7-710b-4d27-a4cb-c601b3f3fa80n%40googlegroups.com.

No comments: