How can I enable backspace key in VI?

4

2

I have bare-bone FreeBSD installation. No package installed. And VI doesn't accept backspace key. (I pressed backspace key but nothing happen) How can I enable backspace key in VI?

Oh, and I'm using Mac, and controlling FreeBSD on VM or via Terminal.

Eonil

Posted 2011-03-01T13:12:00.593

Reputation: 4 206

What do you mean "doesn't accept backspace"? Do you see something like ^H, nothing at all or what? – Eelvex – 2011-03-01T13:22:12.750

Answers

3

You could try this in the terminal before running vi:

$ stty erase [Ctrl-V] [Backspace]

where [Ctrl-V] is pressing Control + V and [Backspace] is pressing the backspace key.

Majenko

Posted 2011-03-01T13:12:00.593

Reputation: 29 007

1

What helped me - in Terminal Preferences - select Advanced tab - check the "Delete sends Ctrl-H"

user193492

Posted 2011-03-01T13:12:00.593

Reputation: 11

Hello, and welcome to Super User. Your answer would be far more useful to the asker as well as future visitors if it explained why and how this solves the asker’s issue. SU is meant to be a community Q&A site, which works best when answers are canonical for the issue at hand (you might want to read the [answer] guidelines). – kopischke – 2013-01-28T19:01:18.010

0

From :h backspace-delete:

Backspace and Delete keys *backspace-delete*


In 3.0 both the delete key and the backspace key worked as a backspace in insert mode; they deleted the character to the left of the cursor. In 4.0 the delete key has a new function: it deletes the character under the cursor, just like it does on the command-line. If the cursor is after the end of the line and 'bs' is set, two lines are joined. |<Del>| |i_<Del>|

In 3.0 the backspace key was always defined as CTRL-H and delete as CTRL-?. In 4.0 the code for the backspace and delete key is obtained from termcap or termlib, and adjusted for the "stty erase" value on Unix. This helps people who define the erase character according to the keyboard they are working on. |<BS>| |i_<BS>|

If you prefer backspace and delete in Insert mode to have the old behavior, put this line in your vimrc:

    inoremap ^? ^H

And you may also want to add these, to fix the values for <BS> and <Del>:

    set t_kb=^H
    set t_kD=^?

(Enter ^H with CTRL-V CTRL-H and ^? with CTRL-V CTRL-? or <Del>.)

If the value for t_kb is correct, but the t_kD value is not, use the ":fixdel" command. It will set t_kD according to the value of t_kb. This is useful if you are using several different terminals. |:fixdel|

When ^H is not recognized as <BS> or <Del>, it is used like a backspace.

Paused until further notice.

Posted 2011-03-01T13:12:00.593

Reputation: 86 075

This is for VIM - not VI. The two are very different in their command sets. – Majenko – 2011-03-01T16:11:45.133

(This question comes up in the Google search results for the "backspace not working" problem in vim.) The instructions in this answer didn't work for me. However, placing set backspace=2 in the vim config did the trick. – vadipp – 2012-11-16T10:53:39.290