Vim autoindent does not work as I expect after "if", "for", "while"; How can I make it work the way I want?

I have automatic indentation in my .vimrc set autoindent file, which moves to the previous indent like this ( β–ˆ - cursor position)

 while (! skynet.selfAware()){ DARPA.funding++;β–ˆ } 

Pressing the carriage input / return button will give

 while (! skynet.selfAware()){ DARPA.funding++; β–ˆ } 

But is there a way to make vim smart enough to realize that a new indentation is required, so starting with that

 while (! skynet.selfAware()){β–ˆ } 

pressing the enter / return carriage key will give

 while (! skynet.selfAware()){ β–ˆ } 

instead

 while (! skynet.selfAware()){ β–ˆ } 
+4
source share
2 answers

Use smartindent . He does exactly what you are looking for.

+6
source

You can try to enable cindent . There are tons of options for controlling how this works, see :help cinoptions-values .

0
source

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


All Articles