Tommy
Tommy

Reputation: 13672

vim make delete operate as backspace

I'm on a Ubuntu server, sshd in through my mac. The key on my keyboard above the | key is called delete, but it operates as backspace on my mac, deleting the character prior to the cursor. I have o press control-delete to get a delete that deletes the character after the cursor.

Before I fixed anything, hitting the delete key in insert mode (on the server via ssh) inserted ^? into the text.

I read this site: http://vim.wikia.com/wiki/Backspace_and_delete_problems where I typed

:fixdel
:set backspace=indent,eol,start

Into my .vimrc. But now my key acts as a delete key where pressing it deletes the character after the cursor, but I want it to delete the character before the cursor. How can I switch this functionality?

Essentially even though my key is physically called delete, it operates as backspace on my mac, and I want it to operate as backspace when using vim via ssh on a server.

Upvotes: 1

Views: 1500

Answers (1)

xaizek
xaizek

Reputation: 5252

Solution 1

If you already have :fixdel, then you can instruct Vim to do interpret Delete as Backspace in insert mode with this command:

:inoremap <delete> <backspace>

On some configurations this can remap all delete keys.

Solution 2

Alternatively, without :fixdel, that ^? should be possible to remap too, like this:

:inoremap ^? <backspace>

Note that here ^? is what appears when you type that "broken" key, it should be possible to enter it as a sequence of two keys, where the first one is a special "escape" key: Ctrl-V Delete. The effect should be the same, unless keyboard code is mangled somewhere in the middle (i.e. Vim gets invalid sequence on its input).

Upvotes: 2

Related Questions