Vimrc settings to emulate Sublime's parenthesi

2019-02-25 16:45发布

问题:

How do I emulate Sublime text's auto complete behavior for curly braces {} on vim? Basically, when a parenthesis is opened, it should auto close in the same line, and when <CR> is pressed the cursor should go to the next line with a block indentation and } should fall in line with the original indention of the line containing the {. If my question is not clear, this is the default behavior of most code editors when dealing with {}.

回答1:

The Automatically append closing characters page on the Vim Tips Wiki has everything from simplistic mappings to complete plugin solutions. There seem to be issues with the latest Vim 7.4 version, though.



回答2:

There exist many plugins with similar features as Ingo pointed out.

lh-brackets, that I'm maintaining, has the features you describe:

  • { inserts {} and moves the cursor in between (and also inserts a placeholder after the closing bracket
  • hitting <cr> while within a pair of curly-brackets will insert another newline in-between (and indent correctly)