Vim contest: who finds the shortest possible solution of changing an postgreSQL tab into an array ?
Maybe some of you have realised that i became a little obsessed in the last days using vim.
Inspired by this Blog entry I want to start a contest.
Who finds the fastest solution of editing a given postgre table and changing it into an given array ?
What you can win ? Well, the satisfaction of being the only true vim-master of the world :)
That said, here the general framework.
First the table we use in our contest:
col1 | integer | not null col2 | timestamp without time zone | not null col3 | character varying(100) | col4 | numeric | col5 | numeric | col6 | integer | col7 | integer | col8 | numeric | col9 | numeric | col10 | character varying(100) | col11 | character varying | col12 | character varying(100) | not null col13 | character varying | col14 | character varying | col15 | numeric | col16 | numeric | col17 | numeric | col18 | character varying | col19 | numeric |
There are no lines before or after this table, and no spaces before or after this table
This table we want to alter into this:
$ary = array('col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7','col8',
'col9','col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17',
'col18', 'col19');
The array has to begin at the left topmost corner too
We start at the top left corner in normal mode
textwidth is set to 78
tabstop is set to 8
shiftwidth is also set to 8
all relevant settings i did not mention here shall not be altered from the default configuration
only standard keymappings of vim 7.1 are allowed, no abbreviations
So the best would be to start it like this: vim -u NONE
The ending position of the cursor does not matter, as well as the mode in which you are when you finished
Every keystroke will be counted, so when a shift- or ctrl-key has to be pressed, this counts as an extra keystroke
I use a German keyboard so my keystrokes will differ from the English ones, of course, for those people with different keyboards, when someone with an English keyboard finds the fastest solution, the keystrokes of the other keyboards will be translated to the English one and vice versa :)
As i am pretty sure there will be some obscurities because of the endless possibilities of vim, they will be discussed and added to the framework.
So let me begin with my first solution:
<CTRL-V>GI’<Esc>qqelC’,<Esc>+q18@qs);<Esc>ggi$ary = array(<Esc>VGq
This makes a total of :
57 keystrokes
on a German keyboard, this will be converted to the amount of keystrokes on an English keyboard, if needed. I’m very sure it takes less strokes on an English one.
Lets see this test also as an benchmark for other editors, but if you use the mouse, every move of the arm counts as 1 keystroke, so when you grab for the mouse and click something, this counts as 2 keystrokes, not counting the clicks of course, if you move your arm after the click back to your keyboard again, this counts as another keystroke, if you click something else this move counts as another keystroke, if the icons are side by side then only the click is counted.
We have our first winner, this is Matt’s solution:
i$ary = array(<Esc>lqqi’<Esc>f C’,<Esc>+q99@qs);<Esc>vggJX
Makes a total of:
53 keystrokes (converted to a German keyboard)
Actually the last X is from me, but i’m cocksure he would find that out for himself :)
And the master is on the road again, here my improved version of Matts version:
i$ary = array(<CTRL-O>qq’<Esc>f C’,<Esc>+q99@qs);<Esc>vggJX
Makes a total of:
52 keystrokes
technorati tags:vim, contest, fast,benchmark, editing,efficient,pragmatic





first try, 49 characters:
qqi’f C’,+q99@qs);ggi$ary = array(vGJ
second try, 46 characters:
i$ary = array(lqqi’f C’,+q99@qs);vggJ
I essentially improved your own solution, incorporating your visual block into the macro and assumed the solution would be less than 99 lines :P
following tries gave longer results, like this one (56 characters):
:%s/\(col\d*\).*\n/’\1′, /
i$ary = array(A);
Have to check your other solutions but your second one did not removed the last comma :) on my keyboard it took 51 keystrokes, adding the X you need to remove the comma we have a total of 53 keystrokes so you made it to the hall of fame, thanks for sharing your knowledge :)
Peculiar, with my vim the s before the ) drops the comma following the col19′.
Credit for finding the missing escapes (I just noticed text enclosed in angular brackets is stripped).
i have beaten your solution :)) i post it in the article…
“postgre”? What’s that?
If you mean the database, it’s “PostgreSQL”, pronounced “post-gres-cue-ell”, usually abbreviated by reducing the last two syllables, hence “post-gres” or “postgres”. Or maybe “pg”. Never “postgre”. You don’t even *say* “postgre” while saying the name. :)
Man, pronouncing politics :) i corrected it to your liking, so the s in postgres stands actually for system and not structured ?
But anyway, this is not the issue of this article :)
[...] to filename.txt : : After my fulminant efficient vim-keycombination for tableediting (see this article) i : challenge everybody to find the shortest keycombination to fulfill this : task. : : I start [...]
Advanced Command-Line Editing « Minimalistic Transparent X-Desktop said this on September 11, 2007 at 7:44 pm |
Thanks!,