Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I realize that the "command" for erasing a letter is x, but if you're seriously just erasing like 3-5 letters, is it really beneficial at all to press ESC + hhhhh + xxxxx?

In vim, is there any reason we can't use the backspace?

share|improve this question
    
Backspace works fine for me. –  Ignacio Vazquez-Abrams Mar 4 '12 at 6:22
    
That depends on what is the context, without any more info Esc + 4Xx would do the same. If you give a sample of the text maybe we could see if there is a shorter way. –  Raimondi Mar 4 '12 at 6:26
    
Is this question about what the point of the x command is, or about how to actually use the backspace key in vim? –  NReilingh Mar 4 '12 at 6:34

4 Answers 4

up vote 4 down vote accepted

Since your your typing sequence starts with <Esc> I assume you are in insert mode, right? If so, you can type <C-w> to delete the word on the left of the cursor without leaving insert mode.

Hitting <bs> works in insert mode as well for single characters, there's no real need to get out of it if you only need to delete a few of the characters you just typed.

x is "the" command to erase a letter in normal mode but it only works alone (x) or with a count (5x), same for X. There are many situations where you need to act on a whole word or two, or what's between a pair of parenthesis, or until a specific pattern forward, or until and including a specific letter backward… In such situations, you should use d in combination with motions.

share|improve this answer
    
And then there's '<C-o>' in insert mode, which lets you enter a single normal mode command without really leaving. –  Magnus Mar 6 '12 at 17:11

In command mode, Backspace is used to move cursor to left. If you want to use it as expected, use following command in command mode:

:nnoremap <bs> X  

Add it in your .vimrc file if you want permanent change.

share|improve this answer

Instead of ESC hhhhh xxxxx, try d5h.

share|improve this answer

You can use the mapping Sachin Shekhar suggested or do it "the Vi way", but there is in my opinion a better way:

The backspace setting controls how the Backspace key works. Putting this in your .vimrc makes the Backspace key work the way most people expect:

set backspace=indent,eol,start

Do :h 'backspace for more information.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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