Most of you have already switched over to Mac (and if you have -and haven’t switch to TextMate may god have mercy on your soul.)
Me - I’m sticking to VIM. (I always meant to switch over to Emacs but I just never got there - for those of you who want an idea of how crazy Emacs is - Check This Out).
Today I learned two things that turn out to be seriously useful.
In VIM, you can do multi-line search and replace with
%s/bob/Robert/g
That line will replace all occurances of bob with Robert. The problem comes in when you have a url or file path. I ended up writing it like this
%s/\/home\/bob/\/home\/robert/g
Notice all those backslashes? They’re as annoying to type in as they are to read. When you paste a url it gets even worse.
It turns out you can use a different delimiter just choosing something else -
%s'/home/bob'/home/robert'
All this time and I didn’t know you could do that - man it makes it easier.
Now on to the next issue.
%s/.*bob.*//g
That will replace any line containing “bob” with an empty line.
So
mike bob sam bob brett
would become
mike sam brett
Those pesky blank lines can be annoying. It would be nice if there was a simple way to strip them out in VIM
Turns out there are two different ways
:v/./d
or
:g/^$/d
It turns out that the v will do the action for anything that doesn’t match - while the g must match. I haven’t figured out if there is a way to confirm the change before it happens but at least it solved the basic problem. (More tricks can be found here under vi Tricks)
Leave a Reply
Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)