How to put a semicolon at the end of each line ;

I’m not very fond of copy-paste programming, or copy any large chunk of text into my program and make code out of it.

However, sometimes I have to. When it’s not defendable to write a file parser to parse one file once.. It’s usually when validating something and it’s necessary to get a set of test-data into your program with the least possible effort.

Have you ever gone through a 100-rows or more file and put [ ] ; – { } ( ) \ / in the beginning or end of each line? I have. Lots and lots of times. Until I discovered gvim.

Now I write nice little commands like

%s/asdf/ghij/g	- Replace asdf with ghij in entire file.
%s/$/;/g	- Add semicolon to the end of each line
%s/^ ;//g	- Delete semicolons from previously empty lines..
%s/^/\t/g	- Add tab to beginning of each line
g/asdf/d	- Delete all lines containing asdf
g/asdf/d2	- Delete 2 lines from every line containing asdf.

I don’t remember all pages I read to create these macros but this was probably one of them.

Leave a comment