mb14
mb14

Reputation: 22596

Command in VIM to replace something by the same character many times

Is there a vim command to replace something (a word, an inner object, a motion, etc) by a character but as many time as there are character to replace.

Exemple: The cursor is at the beginning of the word foo I want X and replace foo by XXX.

(I don't want to have to count the number of letter, so 3rX is not a valid answer)

I don't want a script or a mapping, I just want to know if there is already a command to achieve that.

Upvotes: 3

Views: 270

Answers (4)

sarnold
sarnold

Reputation: 104050

Similar to Colin's answer, but using the "inner word" selection lets you be less picky about the cursor position:

viwrX

visual inner word replace X

Upvotes: 4

Xophmeister
Xophmeister

Reputation: 9211

verX in normal mode to replace a word with Xs

Upvotes: 4

lucapette
lucapette

Reputation: 20724

If you have the cursor at the beginning of a word then you can do the following:

  • v Go in visual mode
  • w Select the word ( here you can use other motions too)
  • r replace with
  • X here you puts the character you want to use.

Upvotes: 4

Colin Fine
Colin Fine

Reputation: 3364

I think this works:

verX

Of course the 'e' could be a different movement command.

Upvotes: 8

Related Questions