2

Is there a plugin that will help with matching parentheses in vim? For example, in TextMate I can do something like this, where it will match parentheses:

enter image description here

If I type in ( it will automatically add in a matching parens, (), and if I type something in and accidentally re-type the closing parenethesis, it will ignore that. In other words, I could type in hello( or hello() and both would produce hello(). What would be the best way to do this in vim?

Note: please watch the video above, it's quite a bit more complex than just the inoremap ( () for example.

David542
  • 104,438
  • 178
  • 489
  • 842
  • I found this [project](https://github.com/jiangmiao/auto-pairs) on github which implements inserting parens, brakcets and quotes in pairs – adamkgray Jul 23 '20 at 03:26
  • 1
    There are many. I'm even been maintaining [one](https://github.com/LucHermitte/lh-brackets) for ages. SO doesn't like external sites, yet there is a [non extensive list of wikia/fandom](https://vim.fandom.com/wiki/Automatically_append_closing_characters#Plugins). Feel free to complete. – Luc Hermitte Jul 23 '20 at 07:18
  • @LucHermitte wow that's a lot of code to implement matching brackets and such! I honestly thought I'd write one or two lines of code to do the matching, but it turns out to be about 100x more complex than I had though. Thanks for the link! – David542 Jul 23 '20 at 19:54
  • @David542, the _insert pair_ mappings for asymmetric pairs is simple to write even when we want to support _redo_. Things start to become a little bit more complex when we don't want expansion within comments or strings, or worse, in the case of symmetric pairs like quote characters, dollars in LaTeX -- indeed in that case, the mapping may instead trigger a _jump over_. lh-brackets is even more complex as it uses placeholders, it permits to deactivate/reactivate insert mode mappings, it automates deletion of empty pairs, and after 15y I wanted a simple syntax to define all possible mappings. – Luc Hermitte Jul 24 '20 at 08:05

1 Answers1

0

I use delimitMate for this and it works great! It handles creating parens and curly braces for you and also allows you to type over the closing parens/brackets as you would expect.

here are some installation instructions for common vim configurations if you would like to give it a try.

sammyt
  • 216
  • 2
  • 9