Search code examples
vimdindentation

Is it possible to modify the cindent rules for one case in vim?


I am currently using vim as my editor for programming in D. The indent rules are pretty much identical to C, but I've run into a case that vim doesn't handle by default. In D, case statements can take strings which are not properly handled by cindent.

For instance, this works:

switch(blah)
{
case 1:
    // something
case some_variable:
    // ...
}

But not this:

switch(blah)
{
    case "yark":
        case "flurb":
    // something
    case "...":
        // ...
}

Is there some way to override that single rule in a custom indent file, or would the entire cindent ruleset have to be reimplemented?


Solution

  • Try Vim 7.3. The indentation rules introduced in this version mainly for JavaScript also fix this particular situation.

    With Vim 7.3 the code is correctly indented as:

    switch(blah)
    {
        case "yark":
        case "flurb":
            // something
        case "...":
            // ...
    }