Vim Tip of the Day
Every now and then I want to run a given vim command on a bunch of lines. In the past I would have either executed the command and then pressed j. (Hi J-Dot!) to go down and repeat the command. Or if the command were more complex I would have used a macro and done it over and over with @@.
Well, for simple stuff on a range there is an easier way! Lets say you want to delete the first two words of a bunch of lines you have highlighted. This is all you have to do:
'<,'>:normal d2w
SWANK.
(The following includes affiliate links.)
If you’d like to learn more, I can recommend two excellent books. I
first learned how to use vi from
Learning the vi and Vim Editors.
The new edition has a lot more information and spends more time on Vim specific
features. It was helpful for me at the time, and the fundamental model of vi is
still well supported in Vim and this book explores that well.
Second, if you really want to up your editing game, check out
Practical Vim.
It’s a very approachable book that unpacks some of the lesser used features in
ways that will be clearly and immediately useful. I periodically review this
book because it’s such a treasure trove of clear hints and tips.
If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.