jiangmiao / auto-pairs

Vim plugin, insert or delete brackets, parens, quotes in pair
http://www.vim.org/scripts/script.php?script_id=3599
4.11k stars 373 forks source link

Problems with auto-completion for certain pairs #321

Closed pyfb78 closed 3 years ago

pyfb78 commented 3 years ago

So I was using this plugin and then out of the blue, the plugin started to auto-complete for <. This means that when I type <, I end up with <>. This is useful for some languages, but for c++, it is highly annoying. So then, I put the command

au Filetype cpp let b:AutoPairs = {"<": ""}

into my init.vim. However, this lead to another issue. Normally, whenever I would type a brace {, I would end up with {}. And if I wanted to delete the pair, I could delete the first one and delete both of them. However, when I put the command from above in, I would have to delete both of the braces. This is the case for all other pairs as well.

This is a small issue, but I am extremely used to just deleting the first brace. So, is there any way for me to not have auto-completion for < and for me to delete the opening brace only to delete a pair of braces?

pyfb78 commented 3 years ago

Sorry, I realized I had something else installed. I removed that and now it works.

LunarWatcher commented 3 years ago

Like you've already figured out, <: > isn't a default pair. That's not even because of C++, but because of Bash and similar where < doesn't represent a pair ever.

Leaving this bit for the record:

The reason that code breaks the other pairs is because you're saying "I only want these pairs, and nothing else". If you wanna preserve the default, you need AutoPairsDefine({'<': '').

You can also switch to my fork (also the only maintained version of this plugin atm), which has a separate variable for language-specific pairs, as well as a relatively good function for actually initializing them. (bonus: it's also autoload, meaning you can do config in your vimrc without an autocmd). If you do, you can throw this in your vimrc:

let g:AutoPairs = autopairs#AutoPairsDefine([
            \ {"open": '<', "close": '', 'filetype': ['cpp']}
    \ ])

to do the same thing.

Also, if you still want some contextual pairing (works in either variant of the plugin), you can use '\w\zs<': '>' as a pair. Instead of just expanding < blindly, it only expands < if there's any letter immediately in front of it. This means it expands std::vector<>, but not std::cout < (but it will expand if there's no space before the <). Up to you of course, but it's an option if you want certain types of autocomplete for <>