9

Sometimes when entering a command in normal mode you may make a typo, for example if I intend to type 10dk, I might accidentally start typing 19d.

Since the command has not been completed/committed yet, is it possible to delete the incorrect keys using backspace, as such: 19d<backspace><backspace>0dk, instead of having to hit escape and retry the command?

Side question: Is there a Vim term for the data structure which holds the current command before it's committed?

7
  • 1
    Probably, this can be asked as a feature in newer versions!
    – SibiCoder
    May 25, 2016 at 13:21
  • 3
    Related : vi.stackexchange.com/questions/570/…
    – SibiCoder
    May 25, 2016 at 13:39
  • 4
    AFAIK not possible - but, since these sequences are short, I'm not sure what gain would such a feature accomplish. When you have to retry the whole sequence, at least you are "forced" to repeat it until you make no such mistakes ;) (i.e. - repeating builds character! pun intended).
    – VanLaser
    May 25, 2016 at 13:46
  • 1
    @VanLaser A Vimmer's worst nightmare is being "forced" to repeat something ;) Also, I suck at typing and have a blank keyboard so it's not uncommon for me to mess up a command 256 times before getting it right.
    – HellaMad
    May 25, 2016 at 13:50
  • 4
    What could go wrong when a bad typist uses a blank keyboard?
    – romainl
    May 25, 2016 at 14:39

1 Answer 1

3

There is no way to do it and it is normal that there isn't: normal mode commands are generally pretty short and can be cancelled with Esc if you mess it.

A possible workaround would be to use the :normal command. It makes the process longer but for example if you type :normal 10j in the command line, Vim will execute 10j as if you typed it in normal mode. (See :h :normal)

You could also add these lines to your .vimrc:

nnoremap <F4> :call NormalModeCommand()<CR>

function! NormalModeCommand()
    let command = input("Normal command: ")
    execute "normal " . command
endfunction

They create a mapping (here F4 but use whatever you want) which will call the function NormalModeCommand().

The function allows you to type a string in the command line and then execute the string you typed as a normal mode command. As you type the string in the command line you can correct it as every other command. Of course it is not ideal but once again Vim isn't meant to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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