152

I just did some changes to the .vimrc file and .bash_aliases file and from that time I can't delete words with backspace key.

My .vimrc file has:

set nocompatible

set number
set incsearch
set autoindent
set ruler
set autowrite
set smarttab
set linebreak
set spell
set et
set title

set mouse=v
set history=50
set tabstop=4
set matchtime=2
set matchpairs+=<:>

syntax enable
filetype plugin indent on
filetype indent on
set sw=4

map <f2> :w\|!python %

hi SpellBad ctermfg=000 guifg=#000

And my .bash_aliases file has two line for Vim:

alias vim="vim -c 'startinsert' -u ~/.vim/.vimrc"
alias vi="vi -c 'startinsert' -u ~/.vim/.vimrc"

My ~/.vim directory doesn't have a single plugin or script, so there's isn't any chance that plugin will cause this.

~/.vim/.vimrc is a symlink. The actual .vimrc file is in ~/vimrc/ directory which is a git repository.

2

9 Answers 9

272

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.

4
  • it's still doesn't work for me =/ i've got set backspace=2 set backspace=indent,eol,start fixdel
    – holms
    Commented Aug 2, 2013 at 11:07
  • 2
    @holms try set backspace=2 alone Commented Jan 7, 2014 at 11:30
  • What the reason for such defaults where backspace is just moving caret to the left? Commented Dec 11, 2017 at 10:54
  • 2
    If you use vim80 above, see this : stackoverflow.com/questions/52438373/…
    – Lewis Chan
    Commented Sep 21, 2018 at 7:41
43

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
2
  • Running this also color coded the text I was editing instead of it being completely gray (I was editing a BASH file) and it started telling me when I entered INSERT mode.
    – Gerry
    Commented Apr 27, 2021 at 15:03
  • This fixed my problem (same as OP with the weird backspacing). Sometimes the simplest solution is the correct one. Thank you!
    – cjaro
    Commented Jan 6, 2022 at 18:04
14

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
13

Nothing from above worked for me. Tried CTRL+backspace it saved me

0
6

I have compiled vim8.2 from source.Then I encouter this problem. After insert source $VIMRUNTIME/defaults.vim in .vimrc. BackSpace works.

4

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.

2

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.

1
  • This is kinda an old thread, but for me what's happening is that in vimtutor the backspace key is not working in insert mode, but in vim it does work in insert mode
    – user5849816
    Commented Apr 21, 2023 at 15:59
1

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.

1
  • 1
    Perhaps, these packages install different vimrc file(s). Commented Sep 27, 2015 at 13:31
1

Many a times it is also a function of the getty type selected if one is using an SSH client like Putty or some such. Most preferable would be to use vt100+ as it is the most standard emulation.

I already had :fixdel which was not working. I had to remove it and replace it with the first suggestion to get it to work

1
  • I converts back space into delete
    – ashish
    Commented Sep 21, 2021 at 6:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.