One of the best investments I’ve ever made is to be proficient with a good cross-platform editor, in my case Vim. It took me a good few months before I really became comfortable with it, but those few months’ struggle yielded huge dividend since then!
So after years of Vim usage, I consider myself a power user. Yet from time to time, I come across some nifty tips that remind me why I fall in love with it in the first place: the sense of wonder, awe, beauty, and intelligence of its creators!
Here are two things I learned recently:
Yesterday I was doing some email log analysis, and had a bunch of email addresses in my file. And I thought, wouldn’t it be nice if I could sort those addresses based on domain names? So I searched the web, then looked through :help sort. Sure enough, I can absolutely do that.
Say you’ve got the following lines:
person1@b.com
person2@a.com
person3@a.com
person4@c.com
person5@a.com
To sort them based on domain names, type :sort /.\+@/ in normal mode will do just that.
However, before deleting them, sometime it is a good idea to save them away. To do that, run
:g/pattern/yank CapitalLetter
This command will put matching lines into a register. Let use X as an example. At a different buffer, you can run
"Xp
And it’ll paste those lines!