Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Key is changing letter case in Vim

Tags:

vim

I'm trying to get into Vim. I'm running it in the terminal on OS X.

Anytime I hit the delete key, it simply changes case of that letter instead of deleting it. When I SSH into my server and use Vim there, it deletes normally.

Any ideas what may be going wrong?

like image 940
Nicky Hajal Avatar asked Jul 12 '10 17:07

Nicky Hajal


People also ask

How do I delete something in Vim?

Deleting a single line in Vim editor: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.

How do I delete a whole text in Vim?

Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.

How do I select all in Vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.


1 Answers

The problem

The Del key generates the code ^[[3~ in my urxvt terminal on GNU/Linux, and might generate a similar code in your OS X terminal.

My theory is that Vim for some reason doesn't recognize any keybinding for the delete key, and simply tries to interpret the string ^[[3~ as input instead. ^[ is the keycode for the Esc key (which puts you in normal mode), and ~ is the Vim command for changing the case of a letter (from normal mode).

You can confirm the keycodes I mentioned by pressing Ctrl+V Esc and Ctrl+V Del from insert mode in Vim. Ctrl+V means that the next character should be inserted as text instead of being interpreted by the editor.

The solution

As for the solution, try editing your Vim configuration file (presumably ~/.vimrc):

vim ~/.vimrc

And append the following code to it:

nmap <Ctrl-V><Del> x
imap <Ctrl-V><Del> <Ctrl-V><Esc>lxi

I hope this helps :)

like image 159
jabirali Avatar answered Oct 09 '22 03:10

jabirali