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):
47
#121 - Solomon White / @rubysolo

02/08/2011 at 05:24PM

47
#122 - Xavier Nayrac / @lkdjiin

12/29/2011 at 03:04PM

47
#123 - Yi EungJun / @semtlnori

09/23/2012 at 12:15PM

47
#124 - michael / @pfista

07/02/2013 at 02:39PM

47
#125 - Gurukandhamoorthi / @Gurukandhamoor1

08/09/2017 at 03:30PM

49
#126 - Israel Chauca F. / @Raimondi

12/28/2010 at 11:37PM

49
#127 - Martin Petrov / @mgpetrov

08/23/2012 at 08:25PM

49
#128 - Arto Vuori / @dhpe

08/30/2012 at 08:02PM

50
#129 - krazylegz / @krazylegz

12/28/2010 at 11:24PM

51
#130 - Jonathan Wallace / @jonathanwallace

12/29/2010 at 03:37AM

51
#131 - Alain Gilbert / @alain_gilbert

12/30/2010 at 06:43PM

51
#132 - Eivind Jahren / @HaskellElephant

03/27/2011 at 07:09PM

51
#133 - Nico Kruger / @nicok_za

11/09/2012 at 12:14PM

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

01/15/2011 at 08:38PM

52
#135 - Birkir Ólafsson / @Birkirlafsson

07/27/2014 at 01:38PM

55
#136 - うえっち / @uh_tomo

12/04/2012 at 05:14PM

55
#137 - くま55 / @kumack55

04/03/2013 at 01:38PM

57
#138 - Eric Holmes / @ejholmes01

12/30/2010 at 05:22AM

57
#139 - Travis Jeffery / @travisjeffery

11/16/2011 at 05:11AM

59
#140 - Jeroen / @teranex

03/04/2011 at 12:29AM

68
#141 - primitiveworker / @primitiveworker

12/30/2010 at 12:17AM

68
#142 - Andrey A. Ugolnik / @andreyugolnik

01/19/2011 at 10:58PM

69
#143 - drio / @drio

12/30/2010 at 10:27AM

81
#144 - Eric Allen / @ericpallen

12/28/2010 at 11:19PM

85
#145 - Kudryavtsev Alexandr / @kudryav_a

12/16/2012 at 07:29PM

126
#146 - Felipe Jaramillo F / @mrfelipe

06/06/2014 at 10:18PM