23

Does anyone know how to map the backspace and delete keys in Vimscript?

3
  • 29
    If you do :ctrl-k and 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? Commented Jun 28, 2011 at 14:09
  • 2
    @Frederik : You should turn your comment into an answer. In insert mode, you can also use ctrl-v to insert the key alias (in a vim script for example) Commented Jun 30, 2011 at 14:04
  • Refer to :help key-mapping, particularly :help map-special-keys for a thorough explanation. Commented Aug 2, 2011 at 21:39

2 Answers 2

28

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.

Sign up to request clarification or add additional context in comments.

Comments

5
imap <Bs> BACK
imap <Del> DELETE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.