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):
34
#61 - Tim Dean / @Tmdean

01/05/2011 at 08:47PM

34
#62 - Dezső Zoltán / @zakiazigazi

01/22/2011 at 08:02AM

34
#63 - Rob Ciaccio / @RobertoCalavera

01/23/2011 at 03:53AM

34
#64 - William Dunand / @wdunand

12/08/2011 at 06:49AM

34
#65 - Tesnorth / @Tesnorth

01/31/2012 at 04:36PM

34
#66 - 無ん垢の叫び / @john_ababa

02/22/2012 at 02:04PM

34
#67 - Yann Moisan / @YannMoisan

02/02/2013 at 01:35PM

34
#68 - cj / @cj01101

08/27/2013 at 02:21AM

34
#69 - brett / @brettyukich

09/23/2013 at 04:46AM

34
#70 - DHM / @DHM29978992

05/15/2018 at 03:10AM

34
#71 - Mihai / @mihaicristiant

03/22/2019 at 07:18AM

35
#72 - Aaron Bull Schaefer / @elasticdog

12/28/2010 at 11:20PM

35
#73 - uuu / @uu59

12/30/2010 at 06:34PM

35
#74 - Simon's Calf / @simonscarfe

08/31/2011 at 08:43PM

35
#75 - Tara Bass / @tara_bass

01/02/2012 at 12:57AM

36
#76 - Charlie Liang Yuan / @_cly_

01/05/2011 at 02:37AM

36
#77 - Ilya Strukov / @i1ey

05/01/2011 at 05:56PM

36
#78 - Hannibal7878 / @Hannibal7878

07/15/2011 at 04:15AM

36
#79 - Jesús Espino / @jespinog

09/06/2011 at 09:23AM

36
#80 - Chris Brown / @engineercyb

07/13/2012 at 03:22AM

36
#81 - Underhill Labs / @underhilllabs

10/30/2012 at 01:49AM

36
#82 - Mikko Loponen / @lopossumi

11/08/2012 at 05:34PM

36
#83 - Tamás Kárándi / @tkarandi

12/06/2012 at 10:42PM

36
#84 - Alec Goebel / @zego5360

01/07/2013 at 02:18AM

36
#85 - devper94 / @devper94

03/16/2014 at 10:20AM

37
#86 - Katie Kennedy / @cappy_haddock

12/30/2010 at 07:47PM

37
#87 - AD / @golferTest101

01/01/2011 at 05:20PM

37
#88 -  Ikhsan Maulana / @ixandidu

01/02/2011 at 09:05AM

37
#89 - Roman Mašek / @romario333

01/05/2011 at 07:46PM

37
#90 - Wesley Wong / @wesleymwwong

01/29/2011 at 09:10AM