Using Visual mode (in particular Blockwise Visual mode) seems to be a perfect solution for me, here.
Since you're only replacing a single character, personally I'd go with Ctrl+V
followed by the motion (such as G
for the end of the buffer), then ri
. That replaces a single character and doesn't go into Insert mode, so you don't need an <Esc>
to leave it.
Using .
to repeat a command isn't really directly available in Visual mode... There's something you can do (and it turns out it works in this case), but it's somewhat different. In this case, you could have selected the lines visually (any of the three Visual modes would work), then press :
(shows up as :'<,'>
) and then complete that command to:
:'<,'>norm .
This uses the :normal
command with a range (which is the range of the Visual selection), to run the .
Normal-mode command at the beginning of each line.
In this case, this works well because you want to execute this command once per line and it turns out you want to execute it exactly on the first non-blank character of a line. (In the more general case of using :normal
with a range, you might want to use a seeking motion with f
or t
etc. to locate the proper location in each line.)
Rather than using a Visual selection, you could also have used a count of 3
followed by :
, which Vim expands to :.,.+2
for the three lines between the current one and two below it. Or you could have used :.,$
(which you need to enter yourself) for a range going from the current line to the end of the file.
I've heard that Visual mode is a sloppy way to do things that can be more "Vim-minded."
I haven't really seen this argument and I definitely disagree with the feeling. I don't think using Visual mode is sloppy at all and it can unleash some of the most useful features in Vim. In particular Blockwise Visual mode allows you to easily accomplish some tasks that would take so much more work otherwise.
I think the argument might be that it's sloppy to start Visual mode and use arrows to select the text to act upon instead of using more efficient motions such as iw
or 3E
or ap
or }
. But the sloppiness there doesn't come from Visual mode, but from using inefficient motions. (I think using v3Ec
is about as good as using c3E
even if the latter is one character shorter.)
In any case, if Visual does the job for you, go ahead and make the best use of it as you can!