Vim is like a resident of a different world. It tends to ignore at least half of all other code editor characteristics. And that is both a good thing and a bad one. If you talk about the good sides, it increases the efficiency and the way it works always does the job better than anything else. But if you ask about the bad sides, you’ll know how hungry it could get. Okay I’m going way too far now. In simple terms, Vim does things a bit differently. This difference brings goodness like speed and efficiency in Text manipulation or so, while this also means that for starters, it’ll be difficult to grasp into the flow. In most scenarios, when you switch from a code editor to the other one, the basics are all the same. You can enter, start typing, save files with Ctrl + s and quit the editor with the close button. Simple. But Vim won’t let you do it all that way.
Following the Vim philosophy, some users have faced issues with the backspace key, formerly being unable to delete anything with it. There are different possibilities to this cause. And we’re gonna list all the ones we found.
Is your backspace key working?
Before you even start blaming Vim for not being loyal, check whether your keyboard is working fine in the first place. If you’ve just given your pc a fresh start in the morning after a gruesome session of coding or so last night, it might be that you stomped your backspace key so hard it stopped functioning out of sheer pressure. Now don’t take this even-handed as a joke. It isn’t totally impossible. Because for many a code editor is what a computing session starts with, in which case, you might have missed out on examining whether your backspace key is even working in other places.
If this does not seem to be the cause, the other sections should definitely have your answer.
Are you running Vim for backspace?
Now this one should fulfill at least half of the people concerned about the backspace key not working in Vim. Because, it is possible that you’re not even using Vim! Most Linux operating systems ship a program by default, which is the Vi text editor – Vim’s so-called ancestor. A lot of people simply tend to think of it as the Vim everyone uses. And there’s a tough reason for this.
If you haven’t installed Vim yet, and if you type “vi” in your terminal, you’ll see that an editor-like thing pops up. Now don’t confuse this with Vim. It’s Vi. One way to recognise whether it’s Vim or Vi is by noticing the startup screen. If you pay heavy attention, you should realize that when you start the Vi editor, there is nothing like a welcome screen or dashboard – it’s all blank and bold. Whereas if you start Vim using the full Vim command, you’ll get a welcome screen, with the version of Vim being the first text, followed by a few other tips.
The reason why this could mess up is because once you have installed the Vim package, you can use both the full vim command or also the vi command to start Vim. When you have the Vim package, the vi command will redirect to the regular Vim, instead of the old Vi editor, even if you may have it installed in your system. A lot of people stick to the habit of typing only vi in hope of starting Vim.
So here’s the thing. The old Vi editor never had support for backspace keys, and don’t ask me why. I don’t know either. You gotta delete text by other means. If this case seems familiar to you, then you might consider checking whether you have Vim installed. If not, do so by using your package manager. A few are listed here.
sudo pacman -S vim
sudo apt install vim
sudo dnf install vim
Did you check the backspace option?
This is the most common one. I won’t need to make it long. But follow me as I say. There’s an option called backspace in Vim that can take 3 values. In older versions of Vim, this option was set to be empty, so a lot of people in the early days could not use the backspace key by default. They had to set it up first. It’s possible you’re one of those people too. You might not be as old, but your Vim version could be whatsoever. The more recent versions of Vim have the backspace key set to all the 3 values by default from the defaults.vim file while compilation, so updating yout Vim could just be enough.
If you still want to stick to the older version, this is what you need to do – Add the following lines in your .vimrc file:
You can also pass a single value of the 3 if you wish so, but you probably won’t. So what does each of them do?
This value allows you to delete automatic indentations, or simply any indentations you write out in Vim. It’s best not to exclude this, as you might face some weird situations where you will not be able to use the backspace key. Look what happens:
This is the end of line value, which, if not passed to the backspace option, won’t allow you to join lines if you delete a line break. This is what you’ll see:
If you had the eol passed, and had pressed backspace on the beginning of a line, it would be joined with the previous line above it. But in our case, it didn’t as we don’t have the eol value passed to it.
If this value is not passed, Vim won’t allow you to use the backspace key any more than what you have Inserted after entering the Insert Mode. This is how it looks like:
Ctrl + H as backspace in Vim
Another way around if the backspace key still doesn’t work for you, would be to use a predefined keybinding in which, which is Ctrl + h. If you try pressing Ctrl + h in Vim Insert Mode, it’ll function just like the backspace key.
If none of the above has helped you, nothing else will. This is pretty much everything that you could do to resolve the backspace key not working in Vim. You might as well try the regular remedy any other tech guy might give you, “Did you try reinstalling Vim”? I guess you have your answer!