Does anyone know how to map the backspace and delete keys in Vimscript?
2 Answers
From Normal mode, you can type : then Press Ctrl+k followed by any key, and vim will tell you how to reference it. For example, from normal mode typing : then pressing Ctrl+k and pressing Backspace results in:
:<BS>
Then you can remap like normal:
:map <BS> :echo 'You pressed backspace!'<CR>
:map <Del> :echo 'You pressed Delete!'<CR>
Obviously you'll want to do something more useful than that, so change the part from :echo onward. Here is a helpful tutorial to get started if you are new to remapping keys in vim.
:ctrl-kand then press a key, vim will tell you how it's known to vim; i.e.<BS>and<Del>. What are you trying to do?ctrl-vto insert the key alias (in a vim script for example):help key-mapping, particularly:help map-special-keysfor a thorough explanation.