Conditional indentation in Vim

How can I assign my own indentation if the condition is met (i.e. the line is included) in the previous line? An example is a single space in an if statement. thanks in advance.

input:

`int main (int argc, char ** argv) {

if (argc! = 1) return (2);

if (argc != 2) return(3); for (...) 

E ("\ n");
} `

output: (using g / if / normal j →) shifts to the right each return line

output: (expected)

 int main(int argc, char **argv) { if (argc != 1) return(2); if (argc != 2) return(3); for (...) 

E ("\ n"); }

In other words, positioning is expected relative to the line, not its previous position. again, thanks for your efforts @kev

+4
source share
2 answers
 :help indentexpr 

You need to create an indent function.

Earlier I used the following link. How to indent Vim Script

You can also look in the vim installation indented folder for examples.

on Max OS X

 /usr/share/vim/vim73/indent 
+2
source

Use these commands to automatically source the C source code file:

 :set syn=cpp 

g g = g

+1
source

Source: https://habr.com/ru/post/1397182/


All Articles