We are working at a client adapting an already developed project so they can do their work with it. The project was developed using django, first with 0.91, then with 0.95, now we are going to use svn trunk. So one of the things that we are using, and a lot, is just plain search and replace. I am currently developing a lot on my Vaio Laptop, using Windows Vista as OS, and Komodo Edit as editor. It has great Find and Replace capabilities, well really i don't know if that could be complicated.
So, the server is a Centos 4, some problemas with the drivers didn't allow us to use our classic FreeBSD, we are still dealing with the issues of using python 2.3 instead of 2.4 which we are used to. So that and the trunk thing are the main reasons to do a lot of searching and replacing.
A great deal of deveolpment is done at a workstation, there it was easy to follow the GUI and just point and click. In Centos it is another story, I use vi or vim normally, even at my workstation at Aureal I use gvim and I love it. But the thing I never learned was to search and replace using plain vi commands. To make things worse I have, like, 2 or 3 points of experience out of 100 in sed. So I knew that it had to be a similar syntax, the classic:
:s/oldstring/newstring/g
So I tried that, but no, it worked only to replace the oldstring in the current line, that was not what I wanted. So once again google knows it all. It gave me the simple and expected answer in the first returned link. It confirmed that the above string just replaces oldstrings in the current line. But, as vi is a great great editor, you can give the command more parameters, so I learned that you could pass a range of line numbers to apply the search and replace, so I just thought that I could use something like this:
:1,$s/oldstring/newstring/g
On a side note, I just recently learned that the $ means "last line". That really helps a lot! But it turns out that there is a shorter way to write this using:
:%s/oldstring/newstring/g
So the % would be equivalent to "1,$".
And thats it, I just learned that this week. And it is useful! I know, for a developer with 3 years of experience not knowing that would be like a sin, but I just never need it like a did today.