Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 4d1a6ed2b8cb3409320000c9

Add fold markers to a .c file

Fold markers can make it easier to navigate source code. Add them to this .c file.

Start file
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void copy(char *to, char *from, size_t count) {
    register n=(count+7)/8;
    switch(count%8){
    case 0: do{     *to = *from++;
    case 7:         *to = *from++;
    case 6:         *to = *from++;
    case 5:         *to = *from++;
    case 4:         *to = *from++;
    case 3:         *to = *from++;
    case 2:         *to = *from++;
    case 1:         *to = *from++;
            }while(--n>0);
    }
}

int main() {
    char *input = malloc(sizeof(char) * 1024);
    assert(input);
    char *output = malloc(sizeof(char) * 1024);
    assert(output);
    copy(output, input, sizeof(char) * 1024);
    return 0;
}
End file
#include <string.h>/*{{{*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
/*}}}*/

void copy(char *to, char *from, size_t count) {/*{{{*/
    register n=(count+7)/8;
    switch(count%8){
    case 0: do{     *to = *from++;
    case 7:         *to = *from++;
    case 6:         *to = *from++;
    case 5:         *to = *from++;
    case 4:         *to = *from++;
    case 3:         *to = *from++;
    case 2:         *to = *from++;
    case 1:         *to = *from++;
            }while(--n>0);
    }
}/*}}}*/

int main() {/*{{{*/
    char *input = malloc(sizeof(char) * 1024);
    assert(input);
    char *output = malloc(sizeof(char) * 1024);
    assert(output);
    copy(output, input, sizeof(char) * 1024);
    return 0;
}/*}}}*/

View Diff

1c1
< #include <string.h>
---
> #include <string.h>/*{{{*/
4a5
> /*}}}*/
6c7
< void copy(char *to, char *from, size_t count) {
---
> void copy(char *to, char *from, size_t count) {/*{{{*/
19c20
< }
---
> }/*}}}*/
21c22
< int main() {
---
> int main() {/*{{{*/
28c29
< }
---
> }/*}}}*/

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 181 remaining solutions by signing in and submitting your own entry
#182 Felipe Jaramillo F / @mrfelipe - Score: 126 - 06/06/14 @ 22:18
$I<Esc>$i<Esc>$$A/*{{{*/<Esc>5Gi/*}}}*/<CR>j<BS><Esc>kjj$A/*{{{*/<Esc><Left><Left><Left><Left><Left><Left>y$jjjjjjjjjjjjjPupujj$pkkkkkkkkkkkkkkkkkkj0y$jjjjjjjjjjjjjjjpjjjjjjjjjpo<Esc>uZZ

0 comments


Created by: @wolever

182 active golfers, 618 entries

Leaderboard (lowest score wins):
30
#1 - h_east (トロッコ6個) / @h_east

01/13/2011 at 04:10PM

30
#2 - Wei Dai / @clvv42

01/13/2011 at 08:53PM

30
#3 - Oleg Roshupkin / @jjjahson

01/25/2011 at 03:57PM

30
#4 - vg / @vimgolfer

02/23/2011 at 10:54AM

30
#5 - Ruy Diaz / @diazruy

03/17/2011 at 06:06AM

30
#6 - Craig H. Anderson / @CootCraig

04/19/2011 at 08:45PM

30
#7 - Justin Love / @wondible

06/10/2011 at 03:56PM

30
#8 - Jason Then / @racc69

08/09/2011 at 12:03AM

30
#9 - sjatkinson / @sjatkinson

08/31/2011 at 03:15AM

30
#10 - Derrick Spell / @dcsesq

09/28/2011 at 03:32AM

30
#11 - Ravil Bayramgalin / @brainopia

10/19/2011 at 01:29PM

30
#12 - vimja / @vimja666

11/05/2011 at 12:32AM

30
#13 - You-Siang Lin / @yslinnctu

11/28/2011 at 12:58PM

30
#14 - Ali Moeeny MD PhD / @alimoeeny

12/16/2011 at 11:49PM

30
#15 - Renat Aksitov / @Korvin79

02/06/2012 at 04:19AM

30
#16 - Zeh Rizzatti / @zehrizzatti

02/06/2012 at 04:20AM

30
#17 - Federico Galassi / @federicogalassi

02/22/2012 at 02:43AM

30
#18 - Pawel Obrok / @mrYapee

03/13/2012 at 08:36PM

30
#19 - Rod Knowlton / @codelahoma

05/26/2012 at 09:44PM

30
#20 - Urtica dioica / @udioica

06/11/2012 at 08:23PM

30
#21 - mwatkward / @AftrschoolSpe

06/25/2012 at 09:19PM

30
#22 - Kerson Hsiao / @KersonHsiao

08/07/2012 at 09:05AM

30
#23 - Charles Gordon / @liberalbias

08/25/2012 at 09:55PM

30
#24 - Conner McDaniel / @connermcd

09/18/2012 at 05:31PM

30
#25 - Vim rocks / @vimrocks

10/06/2012 at 02:51PM

30
#26 - Marcin Szamotulski / @me_coot

12/01/2012 at 01:25PM

30
#27 - Hubba / @HubbaBubbaFett

12/01/2012 at 09:08PM

30
#28 - a24f0600 / @a24f0600

12/14/2012 at 06:04PM

30
#29 - Averell Dalton / @webtwoosucks

01/02/2013 at 11:29PM

30
#30 - Jimmy Mabey / @mabeyj

01/20/2013 at 04:01AM