Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backspace key not working in Vim/vi

Tags:

vim

People also ask

How do I backspace in vi?

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. Here is a list of the most common vi commands.

Why is backspace not working Linux?

Checking Terminal Settings with stty The -a flag will give a human-readable output of the control characters. Look for the "erase" character. If it says "^H," then it uses the older Backspace character. Fortunately, you can also fix this with the stty command.

How do you delete in vi?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.

How do I delete a word in vi editor?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.


To allow backspacing over everything in insert mode (including automatically inserted indentation, line breaks and start of insert) you can set the backspace option:

:set backspace=indent,eol,start

or

:set backspace=2  "compatible with version 5.4 and earlier

By default this option is empty, not allowing you to backspace over the above-mentioned things. This is the standard Vi behavior.

You can put this line to your vimrc file to have it set automatically when Vim starts:

set backspace=indent,eol,start  " more powerful backspacing

Also, starting from Vim 8.0 if no user vimrc file is found, Vim will set backspace to this value by loading the defaults.vim script.


Like a linux-newb, I was on a fresh Ubuntu 18.04 install and my vim editor behaved differently than I was used to on the other machines I use (to include the backspace behavior you're describing). I didn't realize that I was actually using vi and not vim (both of which are executed with vi).

Installing vim and then editing a file brought back the behavior I was used to, including the backspacing working like I was expecting.

sudo apt install vim

My ~/.vimrc file had content set nocompatible. Added another line to the same file to make backspace work -

set backspace=indent,eol,start

And just run

source ~/.vimrc

in the same terminal for change to take immediate effect in same shell. No need to open vi and run

:set backspace=indent,eol,start

I had the same problem on a Debian 7.8 over SSH in urxvt + tmux. I had vim and vim-tiny installed.

Removing vim-tiny fixed the problem.


For me,I had the setting below, however the backspace still doesn't work.

set backspace=indent,eol,start

Finally, I found following line led to this problem.

inoremap <expr><C-h> neocomplete#smart_close_popup()

When this setting is deleted, backspace key works well in insert mode.

Reason: That's because Vim sees CTRL-H as a backspace, and this line makes remapped to neocomplete#smart_close_popup() in insert mode.


For me (Debian server, connected with "Konsole" from other linux), problems with backspace key and arrow keys were solved after uninstalling the vim-tiny package and installing the vim package.