Vi is one of the most powerful text editors, but it really separates the men from the boys. GUI’s are highly over rated - all you want is a big black page. Apart from some clear context colouring what more do you need to write code?
One of Vi’s strengths is pattern matching with search and replace features. Below I have outlined the reasons why developers choose this as their favourite editor.
Search and replace
Search and replace is done using sed syntax which follows the form: which lines, what to look for, what to replace it with and then how much to do.
Firstly we need to specify a range of lines to apply our change to.
- Missing this option out means the current line.
- n - line number n.
- a,b - from line a to line b.
- .,$ - from the current line to the end of the file.
- % - all lines.
Now we specify the command function, which in this case is search. We do that with a single ’s’ character.
Next comes the parameter separator. Most people use a forward slash but you can use anything. If your search pattern has a lot of forward slashes then you don’t have to delimit them if you use a different separator. I use a greater than symbol - ‘>’.
The following lines are equivalent.
Next comes the pattern you are looking for. This is a regular expression which can keep matches in buffers to use in the replacement section.
- [Dd]avid [Nn]ewcomb - camel case match.
- ^davidnewcomb - match davidnewcomb at the start of the line.
- davidnewcomb$ - match davidnewcomb at the end of the line.
- david\(newcomb\) - match davidnewcomb and save newcomb in buffer number 1.
- \(david\)\(newcomb\) - match davidnewcomb and save david in buffer number 1 and newcomb in a buffer number 2.
Add another separator character and now specify what we want to replace the search match with. I’ll use the example above.
- nothing - this is the equivelent to delete the text.
- David Newcomb - make sure you have used camel case everywhere.
- nothing - as above
- nothing - as above
- mr \1 - change my title but keep my surname.
- \1 \2 - add a space between my name.
Another separator character and finally add the scope. Without the search scope the pattern matcher will stop after replacing the first occurance on the line. Adding the global flag ‘g’ will allow the matcher to find and replace all the matches on the line.
This sequence, looks for a comma followed by a zero or more spaces followed by a digit, and save the digit in slot 1. Replace all that text with a comma and the digit from slot 1. Do it for each occurrence on the line.
How do you change:
0000367: Update the site contact us page 00:30
0000368: Correct the new section 00:30
0000369: How to access webmail 00:15
0000367,Update the site contact us page,00:30
0000368,Correct the new section,00:30
0000369,How to access webmail,00:15
ready for CVS paste import to Open Office or Excel.
Simples! Go to the first character on the line, hit escape to enter control mode and type:
Where ESC is pressing the escape key.
How can I remember that!!!! It’s all very simple.
- q - create a macro.
- a - save the macro in slot ‘a’.
- w - the first command in the sequences, move one word forwards.
- 2s - delete the next 2 characters and start editing.
- , - write a comma.
- ESC - to enter control mode.
- $ - go to the end of the line.
- 3b - move 3 words back.
- h - one more character to the left.
- cw - delete the next word and put into editing mode.
- , - write a comma.
- ESC - to enter control mode.
- 0 - go to the start of the line (back to the start).
- q - end the macro definition.
The macro does a whole step and returns to the starting point. Now that the macro is defined you can start using it.
- n - optionally, play the macro n times.
- @ - play the macro.
- a - play macro ‘a’
By the former Chairman of Uni-Lever:
“The person who gets on best, is the person who makes the most of the situation in which they find themselves.”
Following the success of my Eclipse 3.5 - Galileo - New and Noteworthy blog posting, I’ve decided to do the same for Eclipse 3.6 - Helios.
I will update this page when the New and Noteworthy pages become available.
- Eclipse 3.6 M1 - New and Noteworthy
- Eclipse 3.6 M2 - New and Noteworthy
- Eclipse 3.6 M3 - New and Noteworthy
- Eclipse 3.6 M4 - New and Noteworthy
- Eclipse 3.6 M5 - New and Noteworthy
- Eclipse 3.6 M6 - New and Noteworthy (API Freeze)
- Eclipse 3.6 M7 - New and Noteworthy (Feature Freeze)
- Eclipse 3.6 Final (23 June 2010)
For extra information see the Eclipse Helios Project Plan.
You have to hand it to Mike Myers!
Vanessa Kensington: Mr. Powers, my job is to acclimatize you to the nineties. You know, a lot’s changed since 1967.
Austin Powers: No doubt love, but as long as people are still having promiscuous sex with many anonymous partners without protection while at the same time experimenting with mind-expanding drugs in a consequence-free environment, I’ll be sound as a pound!
In order to have an effective build environment we must check-in all the resources needed to build the project from scratch; this includes support libraries and support applications. For example one of my projects arrives as an installable deliverable, but in order to create it we need a Java compiler, Java source, property files, NSIS (A scriptable win32 installer/uninstaller system by Nullsoft), Doxygen (documentation generator), JUnit (unit tester) and a whole host of support libraries.
So in order to truly build the project from scratch all these products need to be saved.
Clearcase, while being an excellent source controller, leaves a lot to be desired when it comes to importing a directory structure into its control.
So lets pretend that we have just finished off our testing and it’s check-in time. For the sake of space I’ll only show you how to check in one of the set of support applications, in this case JUnit.
Our support software is located at:
I would like to import it into:
and then create a clearcase symbolic link called latest to point to
This is a really handy way of testing new libraries without changing lots of aspects of your environment.
- Firstly find out what the name of the view is that you are going to import into. In my case “t2_6_14″.
- Open a command shell as the VOB owner using the command:
runas /user:research\ccadmin cmd
- You are now logged in as the VOB owner so your Z: drive (with the shell) is gone. You only have the K: drive which is used by the views directly.
- In the location where you want to do the import, create a folder with the same name as the folder you are importing e.g.
- Run the import command with full paths:
clearfsimport -recurse k:\t2_6_14\java\libs\junit\latest\* K:\t2_6_14\Quentin\ManagerLibs\junit\junit-4.7
- Hopefully, it should start chugging away.
- When it has finished delete the latest folder.
- Oddly the directory you created will be renamed to “junit-4.7.keep” and a new folder will be created by clearcase called “junit-4.7″, and this will contain the imported files. It is now safe to delete the unchecked-in “junit-4.7.keep”
- As a final touch we will create our symbolic link to join “junit-4.7″ to “latest".
- Checkout parent folder:
- Run the link command:
cleartool ln -s junit-4.7 latest
- Lastly, check in the junit folder.