Which vim mapping/ plugin will help me in auto-indenting when entering inside braces, brackets or any similar characters. For example:

Input {press enter}


    cursor here


I want this behaviour for brackets, parentheses etc also.

  • 3
    This usually works with an indent plugin/expression for your filetype (see :help indent.txt`); which filetype specifically do you want this for? There may already be a setting in the existing indent plugin to change the behaviour of how this works. Aug 3, 2020 at 13:42

1 Answer 1


I guess all bracketing plugins have this behaviour for brackets at least. This is the case of lh-brackets for instance.

And it's quite easy to extend to anything else. The important part is CR+ESC+O, O is what will ensure a correct indent. See this related answer on SO: https://stackoverflow.com/questions/35708395/how-to-move-opening-curly-braces-to-a-new-line-in-vim

This will look like to something like the following (untested)

inoremap <expr> <cr> 
   \ : getline(".")[col(".")-2:col(".")-1]=~'{}\|()\|\[\]\|<>' ? "<cr><esc>O"
   \ :                                                           "<cr>"

Note: you'll also have to activate auto indent in your sessions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.