Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VIM, using . (dot) command as an operator?

Tags:

vim

In VIM, the -powerful- command (the dot command) is used to repeat the last action..

But since it is actually defined as a command not an operator, it is not possible to combine it with a motion since only operator are meant to be used with a motion. (Cf. http://www.viemu.com/vi-vim-cheat-sheet.gif for a refresher)

Is it possible to actually use the dot command (when possible) as an operator?

Here is a little use case: I have some lines, and I append to the first one a word. Then I can type j • to do the same to the next line.. And if I wanted to do this for the first ten lines I should repeat this 8 more times...

If I do 8 • j it will repeat 8 times the modification on the same line, then go down one line..

If I do 8 j • it will actually jump down 8 lines and then do it once.

In fact this is obviously the expected (and correct) behaviour, but is there a way to have the . behave like an operator?

Thank you..

Edit: I found a way to achieve that behaviour based on ephemient answer.

In summary just to use the in the command mode with :norm

  • On the first line, press Ctrl-V to enter visual block selection.
  • Navigate down to the last line (8 j).

At this time, the $ and the Append is not really needed since it is actually registered 'inside' the command. Indeed, the necessity of the is actually to use that last modification and avoid to retype it (particularly useful if it was something more complicated like ci ")

  • Press : to enter the command mode and then type norm .

This seems to work for me..

Remark, when entering in command mode the following text :'<,'> is already present, but I typed the above afterwards, like this :'<,'>norm .

like image 252
SanjiBukai Avatar asked May 13 '26 16:05

SanjiBukai


1 Answers

Try this:

  • On the first line, press Ctrl-V to enter visual block selection.
  • Navigate down to the last line (8j).
  • Press $ to move the cursor to the end of (all) lines.
  • Press A (capital A), type to append your word, then Esc to leave visual block insert mode.
  • The word is now appended to all selected lines.

You can find other suggestions on the Vim wikia.

like image 78
ephemient Avatar answered May 17 '26 09:05

ephemient



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!