vi search pattern for replacing line numbers in code snippet

19 12 2008

This is a useful search and replace pattern for deleting the line numbers in a code snippet…

use this command in vi (the unix based txt editor):

%s/^[0-9][0-9]\s*//g

this will delete (replace pattern with nothing) all the line numbers in the following code snippet (thus cleaning it and allowing you to compile it without first manually editing every line):

...
03 import java.util.List;
04 import java.util.ArrayList;
05 import java.util.Iterator;
06
07 public class Todo {
08 private String name;
09 private String note;
...