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

158 active golfers, 487 entries

Leaderboard (lowest score wins):
36
#91 - Rick de chez Gnous / @GnousRick

07/09/2021 at 11:31AM

36
#92 - POSIX / @po6ix

01/10/2022 at 01:29AM

36
#93 - Qing Liu / @poeminlash

07/02/2022 at 02:50AM

37
#94 - Cap / @cappy_haddock

12/30/2010 at 07:47PM

37
#95 - AD / @golferTest101

01/01/2011 at 05:20PM

37
#96 -  Ikhsan Maulana / @ixandidu

01/02/2011 at 09:05AM

37
#97 - Roman Mašek / @romario333

01/05/2011 at 07:46PM

37
#98 - Wesley Wong / @wesleymwwong

01/29/2011 at 09:10AM

37
#99 - mightyfoo / @mightyfoo

05/25/2011 at 02:14PM

37
#100 - xaizek / @xaizek

07/21/2011 at 06:26PM

37
#101 - Ivan Evtukhovich / @evtuhovich

08/02/2011 at 05:08AM

37
#102 - Dave / @zzdave13

08/02/2011 at 08:06PM

37
#103 - Rambominator / @Rambominator

12/13/2011 at 08:40AM

37
#104 - mattn and 100 others / @mattn_jp

02/02/2012 at 07:11AM

37
#105 - Kristopher Urie / @kristopherurie

02/11/2012 at 06:14AM

37
#106 - Dave Ingram / @dmi

11/21/2012 at 06:36PM

37
#107 - Tom Duijf / @tomduijf

01/29/2013 at 11:26PM

37
#108 - Steve Tjoa / @stevetjoa

01/30/2013 at 08:43AM

37
#109 - ltn614 / @ltn614

09/29/2015 at 10:42AM

37
#110 - Walker Boh / @walker_boh

12/02/2015 at 12:51PM

37
#111 - Andreas Näsman / @andreas_nasman

06/20/2022 at 06:49AM

38
#112 - Matthew Draper / @_matthewd

12/31/2010 at 01:30AM

38
#113 - Guillaume Bonnoron / @gbonnoron

12/31/2010 at 12:44PM

38
#114 - Niels Madan / @nielsmadan

01/23/2013 at 01:19PM

38
#115 - pikaren / @REALpikaren

01/23/2014 at 11:44AM

38
#116 - Skúli Jóhannsson / @skulibj

06/28/2015 at 07:31PM

39
#117 - Mike Plotz / @antisuji

12/30/2010 at 02:08AM

39
#118 - 4L41N / @4L41N1

11/21/2012 at 04:34PM

39
#119 - Daniel / @Daniel00288663

04/04/2017 at 10:21AM

40
#120 - Jordan Lewis / @JordanALewis

12/29/2010 at 08:15PM