Vim Auto-closers Compared
I type {
, Vim types }
for me. Vim has a number of plugins to do this and
each does the job slightly differently.
- delimitMate by Raimondi (484 GitHub stars)
- Auto-Pairs by Miao Jiang (181)
- smartinput by Kana Natsuno (239)
- AutoClose by Karl Guertin (44)
- AutoClose by Townk (212)
My Requirements
- Don’t break HTML templates that use double braces, e.g.
{{name}}
- Create a new block easily, i.e. type
{
and the matching}
is inserted and the cursor is positioned on a blank line between the two, correctly indented. - Handle escaped string terminators
- Don’t break other plugins
- Understand that
"
is the comment character in Vim - BONUS! Press return within a string splits line, adds delimiters and a string concatenation operator.
Feature | delimitMate | Auto-Pairs | smartinput |
---|---|---|---|
HTML templates | Doesn’t work with HTML filetype | ✔ | ✔ |
New block | ✘ | ✔ (type {<CR to open a new block) |
✘ |
Handle escaped string terminators | ✘ | ✔ | ✔ |
Don’t break other plugins | ✔ | ✔ | ✔ |
Vim comment character | ✘ | ✔ | ✔ |
String split | ✘ | ✘ | ✘ |
AutoClose and AutoClose
The AutoClose plugins are much simpler than the 3 tested above. If you’re using one and happy, great. If you’re not using anything, try delimitMate, Auto-Pairs or smartinput.
The Winner: Auto-Pairs
I’m going with Auto-Pairs unless it breaks or I find something better.
I’d be interested to investigate smartinput a bit more, but Auto-Pairs gets the job done with minimal effort.
What About String Splitting?
None of the tested plugins wrap strings. One way to implement this would be to
use formatexpr
and formatprg
, which tells Vim to run lines through a
formatter.