Please forgive me as I'm sure this has been asked before, but my Google fu has really failed me here as I'm not sure what this feature is called.

Given text like this: "Hello ~" with the cursor where the ~ is, is there a plugin that will ignore an inserted " since it's already there?

Most IDEs and code editors have this feature (see: sublime, atom, vscode, visual studio, etc) by default and it helps when you type in (thanks to muscle memory) a single or double quote that's already there. If the algorithm isn't intelligent enough, this "feature" becomes a horrible impediment and a nightmare, but when done right, it can be quite handy (and invisible).


1 Answer 1


It's depends on the bracketing plugin you're using. AFAIK, the more popular ones have the feature. (For instance, it's the case of lh-brackets I'm maintaining)

Of course, if you're using a mapping you've found on the internet or in colleague's .vimrc like

inoremap " ""<left>

it won't be enough, and you'll have to find/write a patch for that mapping.

In that particular case your mapping would become.

inoremap <expr> " (getline('.')[col('.')-1] == '"' ? '<right>' : '""<left>')

Note, that if the bracket characters take multiple bytes, the mappings would need to look like:

inoremap <expr> µ (getline('.') =~ '\%'.col('.').'cµ' ? '<right>' : 'µµ<left>')

But then , you'll want to support redo also, and so on. In the end, IMO, you're best using a plugin where all these features are already implemented. Or nothing at all. Some people really don't like auto-closing/balancing of bracket characters -- which I understand without a close everything feature.


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.