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 145 remaining solutions by signing in and submitting your own entry
#146 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

146 active golfers, 441 entries

Leaderboard (lowest score wins):
30
#31 - xavier kt / @xav_kt

02/03/2013 at 08:48PM

30
#32 - Matt Adelman / @Xavierstein

03/20/2013 at 07:44PM

30
#33 - Trevor Powell / @DoomedBunnies

03/21/2013 at 05:24AM

30
#34 - Marco Hinz / @_mhinz_

05/26/2013 at 05:22PM

30
#35 - Petro Тrouq / @zulolosi

06/23/2013 at 03:29AM

30
#36 - spintriae / @spintriae

10/20/2013 at 04:14PM

30
#37 - John Braxler / @braxler

05/07/2014 at 06:03PM

30
#38 - Jonathan Crossley / @_jcrossley

09/06/2015 at 04:12PM

30
#39 - Jon Krause / @jkrause314

04/10/2016 at 09:49PM

30
#40 - Turkey Man / @lvturkeyman

11/28/2017 at 06:02AM

31
#41 - Matt Tarbit / @mtarbit

01/09/2011 at 09:07AM

31
#42 - Andrey Ivanov / @Bytamine

01/19/2011 at 08:29PM

31
#43 - vansan / @VinceVansan

08/25/2012 at 06:26PM

31
#44 - Brendan Op 't Root / @OptrootB

08/29/2012 at 07:59PM

31
#45 - Darcy Parker / @DarcyParker

10/16/2012 at 10:05PM

31
#46 - James / @Dronak

09/05/2013 at 01:44PM

31
#47 - thasso / @thasso23

11/16/2013 at 07:15PM

32
#48 - Mikel Ward / @mikelward

12/31/2010 at 12:59AM

32
#49 - dominique pellé / @vimgolfisto

01/03/2011 at 10:45PM

32
#50 - Tim Chase / @gumnos

01/08/2011 at 04:24AM

32
#51 - Stephen Morrow / @yawmark

01/26/2011 at 02:22PM

32
#52 - Hu Junfeng / @junfeng

07/15/2011 at 11:39AM

32
#53 - OMF / @exolon

05/29/2012 at 01:52AM

32
#54 - Joonas Pihlajamaa / @jokkebk

02/20/2014 at 09:30PM

33
#55 - Pete Johns / @johnsyweb

01/08/2011 at 12:53AM

34
#56 - dagbrown / @dagbrown

12/28/2010 at 11:58PM

34
#57 - Dan Callahan / @callahad

12/29/2010 at 08:29AM

34
#58 - Akira Matsuda / @a_matsuda

12/30/2010 at 02:05PM

34
#59 - Balkoth / @_Balkoth_

01/01/2011 at 01:26AM

34
#60 - Fer Enaf / @0x00C0FFEE

01/04/2011 at 11:33PM