1

If I'm using replace mode, but I want to keep one or a few characters in a row of the text I am replacing, is there an easy way to skip forward rather than retyping the characters or exiting replace mode and moving and re-entering replace mode?

For example, let's say I'm editing the following text:

Tue Jun 11 20:08:07

And I want to change it to:

Wed Jun 12 20:08:07

I can do this by typing RWed Jun 12<Esc> but that seems unwieldy. I can do it as two separate edits, but I run into this use case often and it seems to me there may be a Vim feature just for this task.

Since I recently learned about :help i_ctrl-y, a feature which blew my mind, I thought it worth asking. Ideally the feature I'm hoping for would allow for repeating the entire replace action with the . key, including preserving the characters in the middle (whatever they might be).

2 Answers 2

1

You want to skip Jun , so you must find a way to move cursor to 11.

You want to use dot repeat, so <c-o> is not an option, as it always splits undo.

That leave you only the arrow keys. To stop it from breaking undo, custom map is necessary:

inoremap <Left>  <C-G>U<Left>
inoremap <Right> <C-G>U<Right>
inoremap <C-Left>  <C-G>U<C-Left>
inoremap <C-Right> <C-G>U<C-Right>

The replace keystrokes are: RWedc-rightc-rightright2, it's dot repeatable.

:h i_CTRL-G_U stopped next cursor movement from breaking undo. Read after the linked doc if you want to know how to achieve the same behavior for <home> and <end>.

Personally i prefer multiple edits and macro repeat.

0

You can bind some keys in insert mode to move to the next word like vim-rsi plugin does making vim readline binding aware or use built-in arrow keys. This would be dot repeatable.

Or you can RWed<C-o>/11<CR>12 to replace Tue to Wed, goto normal mode for a single command, search for 11 and continue replacing 11 to 12.

For your example though I would just go for cwWed<ESC><C-a> -- change word Tue to Wed and increase next number by 1. But that is not dot repeatable.

1
  • Or RWed<C-o>/11/e<CR>2. As dedowsdi mentions, this has probelms with .
    – D. Ben Knoble
    Commented Jul 12, 2019 at 16:35

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.