Home Vim Tip of the Day!
Post
Cancel

Vim Tip of the Day!

Let's say you have to upload a bunch of data to a table and let's say you need to index them with an ID key.

You could just declare the column to auto-increment when creating the table in the database (or, in the case of Oracle, define a trigger/sequence combo to produce those values).

... or you could just generate them beforehand in Vim using line numbers. Yes, line numbers.

Suppose you already have your insert statements set up in vim like this:
insert into tmp_table values (33.832,'GC',131072,18844,502464,0.1015525);
insert into tmp_table values (38.272,'GC',149916,26475,502464,0.1751825);
insert into tmp_table values (52.808,'GC',157547,42326,502464,0.2372075);
insert into tmp_table values (68.815,'GC',173398,55185,633536,0.1455373);
insert into tmp_table values (84.570,'GC',317329,74330,633536,0.1732868);
insert into tmp_table values (167.147,'GC',307334,102686,635008,0.2086538);
insert into tmp_table values (167.355,'Full GC',102686,101944,635008,1.8805190);
insert into tmp_table values (184.915,'GC',338599,123368,642688,0.0918409);
Executing %s/(/\=printf('(%d,', line('.'))/ produces the indexes that you need (if the first column is the index field):
insert into tmp_table values (1,33.832,'GC',131072,18844,502464,0.1015525);
insert into tmp_table values (2,38.272,'GC',149916,26475,502464,0.1751825);
insert into tmp_table values (3,52.808,'GC',157547,42326,502464,0.2372075);
insert into tmp_table values (4,68.815,'GC',173398,55185,633536,0.1455373);
insert into tmp_table values (5,84.570,'GC',317329,74330,633536,0.1732868);
insert into tmp_table values (6,167.147,'GC',307334,102686,635008,0.2086538);
insert into tmp_table values (7,167.355,'Full GC',102686,101944,635008,1.8805190);
insert into tmp_table values (8,184.915,'GC',338599,123368,642688,0.0918409);
Just one more reason to love Vim!
This post is licensed under CC BY 4.0 by the author.

Embedding a CDATA section in your BPEL Response

The Case of the Sudden OC4J Restarts [part 2]