0

I would think this would work to make backspace delete the entire previous word in insert mode:

imap <BS> <C-W>

but it doesn't. Tried in vim 8.0 and neovim 0.2.2 iterm2 if that matters.

Any way to accomplish this?

Update

Per comments below (and after reading the linked question) I've done the following:

  • switched to inoremap (didn't fix)
  • tested the output of :imap <BS>.

The output was the following:

i <BS>    *@<RC>=AutoPairsDelete()<CR>
i <BS>    * <C-W>

Removing the autopairs plugin makes backspacing over words work correctly, but I like that plugin and would like to have both behaviors.

  • 1
    That should work, generally speaking. Did you try :imap <BS>? It looks okay? BTW always use the non-remapping varieties of map (nnoremap, inoremap, etc.) unless you have a good reason to do otherwise. Not saying that's going to fix your problem but at least that variable will be removed from the equation. Also try starting vim with -u NONE to set baseline config. – B Layer Oct 7 '18 at 7:52
  • 1
    B Layer is completely right, for what its worth I wrote a question about how to debug a mapping which you might want to read. You should edit your question with what you've learn in my question and what you mean by "it doesn't work" that should make it easier for us to help you. – statox Oct 7 '18 at 11:11
  • @statox thanks! I figured it out based partially on the canonical you linked, and then doing some more digging/experimentation. – Jared Smith Oct 7 '18 at 18:53
  • 1
    @statox I bookmarked your answer...it'll save me some typing next time. – B Layer Oct 7 '18 at 21:46
  • 1
    @statox It took all of 20 minutes until I found myself posting that link for another question here. :) – B Layer Oct 7 '18 at 22:14
0

Figured it out. First, need to turn off the plugin's handling of backspace:

let g:AutoPairsMapBS = 0

This will cause it not to remap backspace when it loads because of the conditional check in the plugin's code:

if g:AutoPairsMapBS
  " Use <C-R> instead of <expr> for issue #14 sometimes press BS output strange words
  execute 'inoremap <buffer> <silent> <BS> <C-R>=AutoPairsDelete()<CR>'
end

Then I can substitute my own remapping

inoremap <silent> <BS> <C-R>=AutoPairsDelete()<CR><C-W>

That does both. Note that it is necessary to include the plugin's function if you want it to work properly, otherwise typing e.g.

int main () {

}

and the backspace over the { instead of the matching brace being deleted it just gets orphaned and left on screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.