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):
37
#91 - mightyfoo / @mightyfoo

05/25/2011 at 02:14PM

37
#92 - xaizek / @xaizek

07/21/2011 at 06:26PM

37
#93 - Ivan Evtukhovich / @evtuhovich

08/02/2011 at 05:08AM

37
#94 - Dave / @zzdave13

08/02/2011 at 08:06PM

37
#95 - Rambominator / @Rambominator

12/13/2011 at 08:40AM

37
#96 - mattn / @mattn_jp

02/02/2012 at 07:11AM

37
#97 - Kristopher Urie / @kristopherurie

02/11/2012 at 06:14AM

37
#98 - Dave Ingram / @dmi

11/21/2012 at 06:36PM

37
#99 - Tom Duijf / @tomduijf

01/29/2013 at 11:26PM

37
#100 - Steve Tjoa / @stevetjoa

01/30/2013 at 08:43AM

37
#101 - ltn614 / @ltn614

09/29/2015 at 10:42AM

37
#102 - Walker Boh / @walker_boh

12/02/2015 at 12:51PM

38
#103 - Matthew Draper / @_matthewd

12/31/2010 at 01:30AM

38
#104 - Guillaume Bonnoron / @gbonnoron

12/31/2010 at 12:44PM

38
#105 - Niels Madan / @nielsmadan

01/23/2013 at 01:19PM

38
#106 - pikaren / @REALpikaren

01/23/2014 at 11:44AM

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

06/28/2015 at 07:31PM

39
#108 - Mike Plotz / @antisuji

12/30/2010 at 02:08AM

39
#109 - 4L41N / @4L41N1

11/21/2012 at 04:34PM

39
#110 - Daniel / @Daniel00288663

04/04/2017 at 10:21AM

40
#111 - Jordan Lewis / @JordanALewis

12/29/2010 at 08:15PM

42
#112 - Jacob Buete / @JBuete

07/05/2017 at 02:01PM

43
#113 - Mike Marion / @mikejmarion

03/22/2011 at 07:09AM

43
#114 - Tyler / @tylerbindon

03/31/2013 at 05:35AM

44
#115 - Eric Potter / @pottereric

06/09/2013 at 03:06AM

44
#116 - J. SUI / @mitsuigh

07/24/2017 at 09:11PM

46
#117 - Rolf K. / @mindleftbody

06/17/2011 at 12:50PM

46
#118 - drooooooooooo / @droooooooooooo

08/08/2011 at 04:05AM

46
#119 - Oliver Christ / @0liverChrist

10/05/2013 at 10:28PM

47
#120 - Nick / @quinks25

01/10/2011 at 06:05AM