I'm looking for a plugin that will autocomplete closing brackets for me. Furthermore, I'd like it to space and tab the inner block automatically.

I've tried a number of them where if I'm typing python for example, I'll get into situations like this (* represents my cursor):

def myFunc(){

So I get the autocomplete on the }, but it 1) doesnt indent for me and 2) leaves the closing bracket on the same line. Instead, I'd like to be able to do something like this:

def myFunc(){

Where as soon as I hit enter within the {} it will correctly indent for me and shift the closing bracket 2 lines down. This is the case in most languages I use (javascript, CSS etc)

Are there any plugins that can do this?


1 Answer 1


lh-brackets does it indirectly.

When it detects you hit <CR> within a pair of {}, it will insert everything that is required. By default, it'll just insert {}. You'll have to use -nl option of :Brackets to force the newline every time (I went back from this configuration)

It's currently defined only for curly brackets, if you want it for other kind of bracket-pairs, you'll have to adapt this snippet of viml:

if lh#option#get('cb_newline_within_empty_brackets', 1)
  call lh#brackets#enrich_imap('<cr>',
        \ {'condition': 'getline(".")[col(".")-2:col(".")-1]=="{}"',
        \   'action': 'lh#brackets#_add_newline_between_brackets()'},
        \ 0,
        \ '\<cr\>'
        \ )

(i.e. change the condition, or use instead lh#brackets#define_imap() that takes a list of condition+action)

But, brackets in Python? Really? BTW, this language may incur side effects regarding automatic indentation.

  • gah I've been jumping around languages lately and ive got a mix of JS and python in my brain hence the brackets! I'll take a look at that plugin, thanks. Was hoping for something that works out of the box though
    – Simon
    Dec 18, 2015 at 20:12

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.