0

Sometimes I forgot to press ESC to return to command mode and enter :w<enter> in some line I was editing. So I get the following:

some line of code:w
    I was typing
   ^ cursor position

So what I do is pressing ESC+k+A+Backspace+Backspace+ESC+j or something similar.

Someone has a shorter/better/quicker way of doing this?

1
  • 1
    You can map :%s/w:$// to a key and use it whenever you mis-typing.
    – cuonglm
    Jul 30, 2015 at 15:27

3 Answers 3

2

If the extra :w<enter> is the only insertion in that place I use ESC + u (undo).

If not it's just as long as yours but depending on personal preferences/habits it might be faster: ESC + up arrow + J (join) + left arrow + left arrow + x + x (delete current char).

Technically the longer sequence can be saved as a macro and then invoked with just ESC + @ + key (where key corresponds to the register in which the macro was saved) - but I just couldn't get the macros into my habits :)

0
2

C-o u

C-o: normal state for one command

u: undo

Note: this might undo more than you want depending on how much you changed.

2
  • Worked but I didn't understand why or what C-o does. I couldn't find help for C-o. Only for C-O. I imagine they're different commands. I can I read the help for it ? Jul 30, 2015 at 15:17
  • @NelsonTeixeira Use: :h i^o
    – nanny
    Jul 30, 2015 at 19:57
1

With set backspace=2, you should be able to just press Backspace three times.

This is the same as set backspace=indent,eol,start, eol being the most important, it allows you to backspace over newlines.

See Vim | options | backspace or :help 'backspace' (note the single quotes) for more details

4
  • how can I read the help for set backspace so I can educate myself on the vim option ? "help set" doesn't have a backspace option. "help set backspace" doesn't work. Jul 30, 2015 at 15:14
  • I found it. It's on :help set then Ctrl-] in the link to "options-list" on the top of the page. Jul 30, 2015 at 18:23
  • 1
    @NelsonTeixeira If you type Ctrl-D when a :help line is partially entered, vim will list the possible auto completions. Can be very handy when you're not quite sure of the name of the topic you need help with.
    – Wildcard
    Sep 27, 2015 at 16:44
  • @NelsonTeixeira :help 'backspace' or :help bs also work. Note the single quotes in the first one.
    – Mikel
    Sep 27, 2015 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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