Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vimscript: how do you map backspace or delete keys?

Tags:

vim

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

like image 822
dan Avatar asked Jun 28 '11 14:06

dan


People also ask

How do I put backspace in insert mode?

Once in insert mode, you can type in your text. Press ENTER at the end of each line. Use Backspace to delete to the left of the cursor. If you need to move the cursor to another line, or make a change, or pretty much anything else, you need to press ESC to get back to Command mode first.


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.

like image 101
Freedom_Ben Avatar answered Sep 20 '22 19:09

Freedom_Ben


imap <Bs> BACK
imap <Del> DELETE
like image 33
Xavier Nicollet Avatar answered Sep 18 '22 19:09

Xavier Nicollet