How can I fix my delete key in VIM over ssh? (Mac OS X)
Asked Answered
S

4

23

When I use VIM in the terminal on my local machine (Mac OS X Snow Leopard), the delete key is really backspace (i.e., destructive backspace).

When I SSH into a particular server, for some reason it's regular delete (i.e., delete the character under the cursor).

How can I change it to be consistent? I've tried a dozen solutions, but nothing seems to work.

Checking the "Delete sends Ctrl-H" box in Terminal Preferences->Advanced doesn't work -- this is non-destructive backspace.

I've tried about a hundred different key mappings in VIM, to no avail.

Interestingly, the key works as expected when I'm typing commands in VIM (e.g., : <something>) -- it's only screwed up when I'm editing the actual text. Any ideas?

Saurian answered 11/11, 2010 at 19:13 Comment(0)
G
19

This worked for me:

:set backspace=indent,eol,start

I'm not sure exactly what it does but it is listed as a possible solution here and here. I found this line in a vimrc file distributed with Ubuntu where the behavior of the mac "delete" key (otherwise known as the "backspace" key) works as expected without any other configuration.

The behavior I was experiencing was a bell sound (no characters deleted) when pressing the mac "delete" key (otherwise known as the "backspace" key) in insert mode. I am using a compiled version of vim 7.3 on "amazon linux" over ssh from a mac. Pressing <ctrl-v><delete> when in insert mode resulted in ^?.

Gunwale answered 13/3, 2014 at 20:49 Comment(0)
N
8

Couple of ideas to try:

  • In your .vimrc file on the remote server, add this line:

    set term=linux
    
  • In your .bash_profile file (or whatever corresponds to your shell of choice) on the remote server:

    stty erase ^H
    

    Note: to make this work correctly, you must type ctrl-v, then ctrl-h to type the ^H character.

    Also, make sure "Delete sends Ctrl-H" is checked in your Terminal prefs.

Norwich answered 2/7, 2011 at 2:33 Comment(0)
D
5

Try adding

set <Del>=<C-v><Del>

to the vimrc on the target machine. Here you must type <C-v><Del> while being logged on the target machine. If this does not work, check verbose imap <Del>: this should tell you whether some plugin has remapped <Del> in insert mode.

Dali answered 11/11, 2010 at 19:58 Comment(2)
Hi ZyX, tried this but no go. When I hit <Ctrl-v><Del> I end up with a command looking like ":set <Del>=^?". I entered it both at the command line in VIM and in my .vimrc; also tried setting <BS> in the same way, but nothing makes any difference at all. verbose imap <Del> and verbose imap <BS> both say "no mapping found." Very frustrating since, as I mentioned, the key works as it should (as destructive backspace) when I'm actually typing the VIIM command at the :prompt; just goes wrong in the actual document.Saurian
@Saurian Very strange since I can make <F1> work like <Del> with set <Del>=<C-v><F1> <F1>=<C-v><F2>. On all my terminals <Del> sends "^[[3~", but I saw terminals where it sends ^?. What do you mean by «destructive backspace»? Maybe you should try inoremap <Del> <Esc>cl (I use this sequence for deleting previous character in transliteration plugin, it works regardless of backspace and delcombine options). Also try :fixdel command.Dali
P
5

Try this: http://www.alecjacobson.com/weblog/?p=295

I fixed the problem by changing my Terminal.app settings. Under Terminal > Preferences choose Advanced. Check “Delete sends Ctrl-H”. Now, vi and vim should understand the delete key more intuitively.

Note: Mapping the “delete” key in my vimrc file seemed like probably the correct way to do this, but that’s a lot of trouble. Is there any reason not to do it this way?

Poss answered 10/4, 2012 at 3:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.