Neither of the following mappings do anything in neovim in iterm2 on mac

inoremap <C-BS> <Esc><Right>s

inoremap <S-BS> <Esc><Right>s

Is mapping backspace like this even possible?


In general this isn't possible, or will have strange side effects due to the way special keys are handled, but it depends on exactly what your terminal emulator is sending.

You can find out the keys sent to vim by the terminal emulator with <c-v> in insert mode
(:h i_ctrl-v). Press ctrl+v followed by the key sequence you want to check. For example, my terminal, emulating xterm sends the following sequences:
<BS> sends ^? (<C-?>)
<C-BS> also sends ^?
<S-BS> sends ^H (<C-h>)

So vim cannot distinguish between backspace, ctrl+backspace and ctrl+?, nor can it distinguish between ctrl+h and shift+backspace. So to get those mappings to work I could remap <C-h> or <C-?>/<BS> but these would obviously override other important keys. This is due to historical reasons.

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.