Shift + Backspace won't work on Vim for Windows

Viewed 622

Before you mark this question as a double, hear me out because I've looked around and I can't find anything that'll fix my issue.

In Vim for Windows (accessed through Powershell running from CMD in a console), backspace works fine. Pressing Shift (or Ctrl) + Backspace prints a weird looking I to the screen and presses Ctrl+C.

Using :set to see what the keycode for the backspace is on my Vim yields this: "Î^Cx". This makes sense considering the behavior described above. The interesting part is that this keycode obviously is for the normal backspace key. My problem however, doesn't appear when pressing backspace normally, which doesn't make sense to me considering that the normal keycode is this weird collection of characters. It only appears when combining backspace with the shift key.

I don't understand why the backspace key doesn't send ^H or ^?. I've heard that those two options are popular. I assume my terminal is messing this up in some way, but I don't understand why it would be sending a different keycode for backspace when the shift key is pressed.

Thanks in advance.

3 Answers

I solved this issue like this:

imap Î^Cy <BS>

In my (Windows) terminals, Î^Cy is shift-backspace and Î^Cz is ctrl-backspace, and I have remapped them both. If Î^Cx is shift-backspace in your terminal, which it seems like it is, try adding this to your vimrc file:

imap Î^Cx <BS>

I don't know why this happened in your configuration, but you should be able to use inoremap to make it do what you want.

Interactively, you can test my idea by typing this

:inoremap <hit control-V><hit shift-backspace> <hit control-v><hit backspace>

What this will do is create a non-recursive map in insert mode for the escape sequence generated by <shift-backspace> to the escape sequence generated by <backspace>.

In my case, the result looked like

:inoremap ^? ^?

because my <shift-backspace> produces the same sequence as <backspace>, but in your case it should produce something more useful for you.

Once you've figured this out, move it to your .vimrc without the colon, and that will hopefully fix your issue in a lasting way.

Are you having the same issue as me I wonder where this happens in Windows Powershell but doesn't happen in gvim or when you run vim under cmd. If so I think the other responders are correct that vim does nothing different with shift+BS than BS but the Powershell command running it is. It's not an answer, I don't know a way around it other than use gvim. But if you're trying to dig further I'd suggest it's Windows Powershell that's the issue (unless I'm wrong of course) rather than vim.

Related