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 116 remaining solutions by signing in and submitting your own entry
#117 drooooooooooo / droooooooooooo - Score: 46 - 08/08/11 @ 04:05
A/*{{{*/<Esc>vF/y6G$p15jp5Gi/*}}}*/<CR><Esc>kyf/20Gp9jpZZ

0 comments


#118 Oliver Christ / 0liverChrist - Score: 46 - 10/05/13 @ 22:28
qaA/*{{{*/<Esc>q3jo<Esc>qbA/*}}}*/<Esc>qjj@a20G@bjj@aG@bZZ

0 comments


#119 Nick / quinks25 - Score: 47 - 01/10/11 @ 06:05
qaA/*{{{*/<Esc>q3jA<CR><Esc>qbA/*}}}*/<Esc>q2j@a13j@b2j@aG@bZZ

0 comments


#120 Solomon White / rubysolo - Score: 47 - 02/08/11 @ 17:24
qaA/*{{{*/<Esc>q6G@a21G@A5GO<Esc>qaA/*}}}*/<Esc>q20G@AG@AZZ

0 comments


#121 Xavier Nayrac / lkdjiin - Score: 47 - 12/29/11 @ 15:04
qaA/*{{{*/<Esc>q6G@a21G@aGqaA/*}}}*/<Esc>q19G@a5GO<Esc>@aZZ

0 comments


#122 Yi EungJun / semtlnori - Score: 47 - 09/23/12 @ 12:15
3jo/*}}}*/<Esc>v0y15jpGp7k$a/*{{{*/<Esc>v6hy15k$pgg$pZZ

0 comments


#123 michael / pfista - Score: 47 - 07/02/13 @ 14:39
qqA/*{{{*/<Esc>q5GqwA/*}}}*/<Esc>qo<Esc>j@q20G@w2j@qG@w:wq<CR>

0 comments


#124 Gurukandhamoorthi / Gurukandhamoor1 - Score: 47 - 08/09/17 @ 15:30
<Esc>kkkqqA/*{{{*/<Esc>}jq2@qqqA/*}}}*/<Esc>{kq2@q4Gf/i<CR><Esc>ZZ

0 comments


#125 Israel Chauca F. / Raimondi - Score: 49 - 12/28/10 @ 23:37
qqA/*{{{*/<Esc>q}qrA/*}}}*/<Esc>qo<Esc>/ {<CR>@qn@q2k@rG@r:x<CR>

0 comments


#126 Martin Petrov / mgpetrov - Score: 49 - 08/23/12 @ 20:25
4Go/*}}}*/<Esc>0v$hy20GpGpgg$phhvhhr{$vF/y7G$p22G$pZZ

0 comments


#127 Arto Vuori / dhpe - Score: 49 - 08/30/12 @ 20:02
A/*{{{*/<Esc>vF/y/{<CR>3np3np?ass<CR>o/*}}}*/<Esc>vF/y)))kpGpZZ

0 comments


#128 krazylegz / krazylegz - Score: 50 - 12/28/10 @ 23:24
$pa/*{{{*/<Esc>vbly5j$p15jpGA/*}}}*/<Esc>vbly9kp:5<CR>po<Esc>:wq<CR>

0 comments


#129 Jonathan Wallace / jonathanwallace - Score: 51 - 12/29/10 @ 03:37
qqA/*{{{*/<Esc>q4jqwA/*}}}*/<Esc>qo<Esc>j@q20j20G@wjj@qG@WZZ

0 comments


#130 Alain Gilbert / alain_gilbert - Score: 51 - 12/30/10 @ 18:43
4Go/*}}}*/<Esc>vby20Gp29Gp22G$a/*{{{*/<Esc>vb<Right>y7G$p1G$pZZ

0 comments


#131 Eivind Jahren / HaskellElephant - Score: 51 - 03/27/11 @ 19:09
qaA/*{{{*/<Esc>q3jo/*}}}*/<Esc>jj@a20GqbA/*}}}*/<Esc>qjj@aG@bZZ

0 comments


#132 Nico Kruger / nicok_za - Score: 51 - 11/09/12 @ 12:14
qaA/*{{{*/<Esc>q3jjqsA/*}}}*/<Esc>q<Esc>jka<CR><Esc>j@a}k@s2j@aG@szzZZ

0 comments


#133 Thomas Schönwälder / Masei1988 - Score: 52 - 01/15/11 @ 20:38
A/*{{{*/<Esc>vF/y4/{<CR>p3/{<CR>p/}<CR>a/*}}}*/<Esc>vF/y2?}<CR>p:5<CR>po<Esc>ZZ

0 comments


#134 Birkir Ólafsson / Birkirlafsson - Score: 52 - 07/27/14 @ 13:38
A/*{{{*/<Esc>4jj.21G.Ga/*}}}*/<Esc>19G.5Gi<CR><Esc>k.ddki/*}}}*/<Esc>ZZ

0 comments


#135 うえっち / uh_tomo - Score: 55 - 12/04/12 @ 17:14
$qaa/*{{{*/q<BS><Esc>q:5<CR>qba/*}}}*/<Esc>qo<Esc>j$@a:20<CR>@bjj$@a:29<CR>@bZZ

0 comments


#136 くま55 / kumack55 - Score: 55 - 04/03/13 @ 13:38
A/*{{{*/<Esc>F/"qyf/4jP4h3r}0"wy$o<Esc>j$"qp:20<CR>"wp2j$"qpG"wpZZ

0 comments


#137 Eric Holmes / ejholmes01 - Score: 57 - 12/30/10 @ 05:22
qqA/*{{{*/<Esc>qjjjo<Esc>qwA/*}}}*/<Esc>q:7<CR>@q:20<CR>@w:22<CR>@q:29<CR>@w:wqa<CR>

0 comments


#138 Travis Jeffery / travisjeffery - Score: 57 - 11/16/11 @ 05:11
O<Esc>qqjA/*{{{*/<Esc>}q2@qo<Esc>qqkA/*}}}*/<Esc>{q@qO/*}}}*/<Esc>:1d<CR>:30d<CR>ZZ

0 comments


#139 Jeroen / teranex - Score: 59 - 03/04/11 @ 00:29
A/*{{{*/<Esc>vT>"ay3jo/*}}}*/<Esc>v0"byjj$"ap12jj"bpjj$"apG"bp<Esc>:wq<CR>

0 comments


#140 primitiveworker / primitiveworker - Score: 68 - 12/30/10 @ 00:17
$a/*{{{*/<Esc>v6hy))$p))$p)a/*}}}*/<Esc>v6hy((()<Up><Right>a<Esc>p(kO<Esc>p<Esc>:wq<CR>

0 comments


#141 Andrey A. Ugolnik / andreyugolnik - Score: 68 - 01/19/11 @ 22:58
A/*{{{*/<Esc>4ji/*}}}*/<CR><Down><End>/*{{{*/<Esc>20GA/*}}}*/<Esc>29GA/*}}}*/<Esc>22GA/*{{{*/<Esc>ZZ

0 comments


#142 drio / drio - Score: 69 - 12/30/10 @ 10:27
$a/*{{{*/<Esc>0f>lv$h"ay6G$"ap21G$"ap28Ga/*}}}*/<Esc>0lv$h"by19G"bp5G"bpo<Esc>:x<CR>

0 comments


#143 Eric Allen / ericpallen - Score: 81 - 12/28/10 @ 23:19
A/*{{{*/<Esc>F/"ay$jjjo/*}}}*/<Esc>^"by$jjA<Esc>pu"bpu"apjjjjjjjjjjjjj"bpjj$"apjjjjjjj"bp:wq<CR>

0 comments


#144 Kudryavtsev Alexandr / kudryav_a - Score: 85 - 12/16/12 @ 19:29
A/*{{{*/<Esc>v%"1y4jP<Esc>uO<C-R>1<C-R>2F<C-H><Esc>4l4hR}}}<Esc>%%^v%"2y:regi<NL><NL>2jA<C-R>1<C-R>20<Esc>uA<C-R>1<Esc>20GA<C-R>2<Esc>2jA<C-R>1<Esc>GA<C-R>2<Esc>ZZ

0 comments


#145 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

145 active golfers, 439 entries

Leaderboard (lowest score wins):
30
#1 - h_east (トロッコ6個) / h_east

01/13/2011 at 04:10PM

30
#2 - Wei Dai / clvv42

01/13/2011 at 08:53PM

30
#3 - Oleg Roshupkin / jjjahson

01/25/2011 at 03:57PM

30
#4 - vg / vimgolfer

02/23/2011 at 10:54AM

30
#5 - Ruy Diaz / diazruy

03/17/2011 at 06:06AM

30
#6 - Craig H. Anderson / CootCraig

04/19/2011 at 08:45PM

30
#7 - Justin Love / wondible

06/10/2011 at 03:56PM

30
#8 - Jason Then / racc69

08/09/2011 at 12:03AM

30
#9 - sjatkinson / sjatkinson

08/31/2011 at 03:15AM

30
#10 - Derrick Spell / dcsesq

09/28/2011 at 03:32AM

30
#11 - Ravil Bayramgalin / brainopia

10/19/2011 at 01:29PM

30
#12 - vimja / vimja666

11/05/2011 at 12:32AM

30
#13 - You-Siang Lin / yslinnctu

11/28/2011 at 12:58PM

30
#14 - Ali Moeeny / alimoeeny

12/16/2011 at 11:49PM

30
#15 - Renat Aksitov / Korvin79

02/06/2012 at 04:19AM

30
#16 - Zeh Rizzatti / zehrizzatti

02/06/2012 at 04:20AM

30
#17 - Federico Galassi / federicogalassi

02/22/2012 at 02:43AM

30
#18 - Pawel Obrok / mrYapee

03/13/2012 at 08:36PM

30
#19 - Rod Knowlton / codelahoma

05/26/2012 at 09:44PM

30
#20 - Urtica dioica / udioica

06/11/2012 at 08:23PM

30
#21 - mwatkward / AftrschoolSpe

06/25/2012 at 09:19PM

30
#22 - Kerson Hsiao / KersonHsiao

08/07/2012 at 09:05AM

30
#23 - Charles Gordon / liberalbias

08/25/2012 at 09:55PM

30
#24 - Conner McDaniel / connermcd

09/18/2012 at 05:31PM

30
#25 - Vim rocks / vimrocks

10/06/2012 at 02:51PM

30
#26 - Marcin Sza / coot_

12/01/2012 at 01:25PM

30
#27 - Hubba / HubbaBubbaFett

12/01/2012 at 09:08PM

30
#28 - a24f0600 / a24f0600

12/14/2012 at 06:04PM

30
#29 - Averell Dalton / webtwoosucks

01/02/2013 at 11:29PM

30
#30 - Jimmy Mabey / mabeyj

01/20/2013 at 04:01AM