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

StackOverflow https://stackoverflow.com/questions/8425217

  •  29-10-2019
  •  | 
  •  

Question

I have auto indentation turned on in my .vimrc file set autoindent which moves to the previous indentation like so ( is the cursor position)

while (! skynet.selfAware()){
    DARPA.funding++;█
}

Pressing enter/carriage return will yield

while (! skynet.selfAware()){
    DARPA.funding++;
    █
}

But is there any way to make vim smart enough to realize that a new indentation is required such that starting from this

while (! skynet.selfAware()){█
}

pressing enter/carriage return will yield

while (! skynet.selfAware()){
    █
}

instead of

while (! skynet.selfAware()){
█
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top