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):
42
#121 - Jacob Buete / @JBuete

07/05/2017 at 02:01PM

42
#122 - shahanavaz m / @shahanavazm

02/19/2022 at 04:15AM

43
#123 - Mike Marion / @mikejmarion

03/22/2011 at 07:09AM

43
#124 - Tyler / @tylerbindon

03/31/2013 at 05:35AM

44
#125 - Eric Potter / @pottereric

06/09/2013 at 03:06AM

44
#126 - 三井 源 / @mitsuigh

07/24/2017 at 09:11PM

46
#127 - Rolf K. / @mindleftbody

06/17/2011 at 12:50PM

46
#128 - drooooooooooo / @droooooooooooo

08/08/2011 at 04:05AM

46
#129 - Oliver Christ / @0liverChrist

10/05/2013 at 10:28PM

47
#130 - Nick / @quinks25

01/10/2011 at 06:05AM

47
#131 - Solomon White / @rubysolo

02/08/2011 at 05:24PM

47
#132 - Xavier Nayrac / @lkdjiin

12/29/2011 at 03:04PM

47
#133 - Yi EungJun / @semtlnori

09/23/2012 at 12:15PM

47
#134 - michael / @pfista

07/02/2013 at 02:39PM

47
#135 - Gurukandhamoorthi / @Gurukandhamoor1

08/09/2017 at 03:30PM

47
#136 - anonymouse / @anonymo65837183

03/27/2022 at 10:52PM

49
#137 - Israel Chauca F. / @Raimondi

12/28/2010 at 11:37PM

49
#138 - Martin Petrov / @mgpetrov

08/23/2012 at 08:25PM

49
#139 - Arto Vuori / @dhpe

08/30/2012 at 08:02PM

50
#140 - krazylegz / @krazylegz

12/28/2010 at 11:24PM

50
#141 - josh / @_zvjos

06/18/2022 at 10:53PM

51
#142 - Jonathan Wallace / @jonathanwallace

12/29/2010 at 03:37AM

51
#143 - Alain Gilbert / @alain_gilbert

12/30/2010 at 06:43PM

51
#144 - Eivind Jahren / @HaskellElephant

03/27/2011 at 07:09PM

51
#145 - Nico Kruger / @nicok_za

11/09/2012 at 12:14PM

52
#146 - Thomas Schönwälder / @Masei1988

01/15/2011 at 08:38PM

52
#147 - Birkir Ólafsson / @Birkirlafsson

07/27/2014 at 01:38PM

55
#148 - うえっち / @uh_tomo

12/04/2012 at 05:14PM

55
#149 - くま ก็็็็็็็็็็็็็ʕ•͡ᴥ•ʔ ก้้้้้้้้้้้ 55 / @kumack55

04/03/2013 at 01:38PM

57
#150 - Eric Holmes / @ejholmes01

12/30/2010 at 05:22AM