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 4d1ac1800a045132c0000011

Reformat a C golf submission

Take this C golf submission (for the "tiny but standards-compliant Hello World program" category, naturally), and turn it into formatted C code.

Start file
#include<stdio.h>
int main(void){puts("Hello world!");return 0;}
End file
#include <stdio.h>

int main(void)
{
    puts("Hello world!");
    return 0;
}

View Diff

--- hw.c	2010-12-28 21:01:54.000000000 -0800
+++ hw-indented.c	2010-12-28 21:04:56.000000000 -0800
@@ -1,2 +1,7 @@
-#include<stdio.h>
-int main(void){puts("Hello world!");return 0;}
+#include <stdio.h>
+
+int main(void)
+{
+    puts("Hello world!");
+    return 0;
+}

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 140 remaining solutions by signing in and submitting your own entry
#141 omelo / omelo - Score: 40 - 12/29/10 @ 08:02
f<i <Esc>o<Esc>jf)a<CR><Right><CR>    <Esc>f;a<CR>    <Esc>f;a<CR><Esc>ZZ

0 comments


#142 johnny / johnnychm - Score: 40 - 12/29/10 @ 11:20
f<i <Esc>o<Esc>jf{i<CR><Right><CR>    <Esc>f;a<CR>    <Esc>f}i<CR><Esc>ZZ

0 comments


#143 Daniel Grippi / danielgrippi - Score: 40 - 12/31/10 @ 19:45
2wi <Esc>o<Esc>6whi<CR><Right><CR><Esc>vhxi    <Esc>6wi<CR><Esc>4wi<CR><Esc>;:x<CR>

0 comments


#144 Dave / zzdave13 - Score: 40 - 07/31/11 @ 22:02
fea <Esc>o<Esc>/{<NL>i<NL><Esc>a<NL><Esc>f;.f;.:se ts=4 et|ret<NL>ZZ

0 comments


#145 Marco Hinz / _mhinz_ - Score: 40 - 05/22/13 @ 09:57
2wi <Esc>o<Esc>jf{a<C-H><NL>{<NL><Esc>f;a<NL><Esc>f}i<CR><Esc>kxkx<C-V>jI    <Esc>ZZ

0 comments


#146 Timothée Gauthier / zmf_tim - Score: 40 - 06/04/18 @ 15:14
ea <Esc>o<Esc>f)/)<CR>a<CR><Right><CR><Esc>f;a<CR><Esc>A<Left><CR><Esc>:%s/<Tab>/    /g<CR>ZZ

0 comments


#147 homerj7648 / homerj7648 - Score: 41 - 12/29/10 @ 05:49
/<<CR>i <Esc>o<Esc>/)<CR>a<CR><Esc> i<CR>    <Esc>/;<CR> i<CR><Esc>$i<CR><C-D><Esc>:wq<CR>

0 comments


#148 Michael Lustfield / Profarius - Score: 41 - 12/29/10 @ 06:34
/<<CR>i <End><CR><Esc>/{<CR>i<CR><Right><CR>    <Esc>/re<CR>.<End>i<CR><Esc>:x<CR>

0 comments


#149 emonkak / emonkak - Score: 41 - 12/29/10 @ 13:30
f<i <C-O>o<Esc>jf{i<CR><C-O>l<CR><Esc>f;a<CR><Esc>f;a<CR><Esc>k<C-V>kI    <Esc>:x<CR>

0 comments


#150 Andrew McDonough / andrewmcdonough - Score: 41 - 12/29/10 @ 18:38
/<<CR>i <Esc>o<Esc>/{<CR>i<CR><Esc>li<CR><Esc>/;<CR>li<CR><Esc>/}<CR>i<CR><Esc>kk2>>ZZ

0 comments


#151 Sammasati / sammasati0 - Score: 41 - 07/15/11 @ 18:41
f<i <Esc>o<Esc>jf{i<CR><Right><CR><Esc>6wi<CR><Esc>4wi<CR><Esc>:%s/\t/    /g<CR>ZZ

0 comments


#152 Sid Kasivajhula / CountVajhula - Score: 42 - 12/29/10 @ 08:10
f<i <Esc>o<Esc>jf{i<CR><Right><CR>    <Esc>f;a<CR>    <Esc>f;a<CR><Esc>:wq<CR>

0 comments


#153 Aaron Bull Schaefer / elasticdog - Score: 43 - 12/29/10 @ 16:20
f<i <Esc>o<Esc>jf{i<CR><Right><CR><Esc>f;a<CR><Esc>$i<CR><Esc>k<C-V>lkllc    <Esc>ZZ

0 comments


#154 Adam / ulbador - Score: 43 - 12/29/10 @ 21:56
/<<CR>i <Esc>/{<CR>i<CR><Right><CR>    <Esc>/;<CR>a<CR><Esc>$i<CR><Esc><<:2<CR>O<Esc>:x<CR>

0 comments


#155 Francisco Dibar / frandibar - Score: 43 - 01/13/11 @ 03:19
:se et sw=4<CR>?^i\|re\|[<{}p]<CR>qqi<CR><Esc>nq4@qi <Esc>ZZ

0 comments


#156 Craig H. Anderson / CootCraig - Score: 43 - 04/22/11 @ 20:10
f<i <Esc>o<Esc>/{<CR>i<CR><Esc>:s/{\|;/&\r/g<CR>:5,6s/^/    /<CR>ZZ

0 comments


#157 togi / togi - Score: 44 - 12/29/10 @ 17:52
2wi <Esc>o<Esc>j:s/{/\r{\r/|s/;/;\r/g<CR><Up>i<Tab><Esc><Up>I<Tab><Esc>ZZ

0 comments


#158 Nick / quinks25 - Score: 44 - 01/13/11 @ 10:54
f<i <Esc>o<Esc>/{<CR>i<CR><Right><CR><Esc>/;<CR>li<CR><Esc>/}<CR>i<CR><Esc>:%s/\t/    /g<CR>ZZ

0 comments


#159 wusher / wusher - Score: 44 - 06/02/11 @ 19:57
f<i <Esc>o<Esc>jf{i<CR><Esc>a<CR><Esc>f;a<CR><Esc>f;a<CR><Esc>kxi    <Esc>kxi    <Esc>ZZ

0 comments


#160 Sasha Koss / kossnocorp - Score: 45 - 12/29/10 @ 07:51
f<i <Esc>jf{i<CR><Right><CR><Esc>4i <Esc>f;a<CR><Esc>4i <Esc>f;a<CR><Esc>4<Up>O<Esc>:x<CR>

0 comments


#161 Aleksander Balicki / alekbalicki - Score: 45 - 12/29/10 @ 14:41
f<<Insert> <Esc>o<Esc><Down>f{<Insert><CR><Right><CR><Esc>f;<Insert><Right><CR><Esc>f}<Insert><CR><Esc>ZZ

0 comments


#162 Andrey A. Ugolnik / andreyugolnik - Score: 46 - 01/19/11 @ 19:00
f<i <Esc>o<Esc>jf{i<CR><Right><CR><Esc>f;<Right>i<CR><Esc>f;a<CR><Esc><Up>Vk<i    <Esc>j^i    <Esc>ZZ

0 comments


#163 Trevor Powell / DoomedBunnies - Score: 46 - 11/28/11 @ 05:22
f<i <Esc>o<Esc>jf{i<CR><Right><CR><Esc>frfri<CR><Esc>f}i<CR><Esc>k:%s/\t/    /g<CR>:wq<CR>

0 comments


#164 Oliver Christ / 0liverChrist - Score: 46 - 02/13/15 @ 18:02
f<i <End><CR><Esc>jf{i<CR><Right><CR><End><Left><CR><Esc>kf;a<CR><Esc>:se ts=4|se et|ret|wq<CR>

0 comments


#165 Chad Waters / cgwaters - Score: 47 - 12/29/10 @ 14:38
f<<Insert> <Esc>o<Esc><Down>f{<Insert><CR><Right><CR>    <Esc>f;a<CR>    <Esc>;a<CR><Esc>:wq<CR>

0 comments


#166 Behnam Esfahbod / zwnj - Score: 48 - 12/30/10 @ 12:50
ea <Esc>o<Esc>eef{i<CR><Esc>a<CR>    <Esc>f;a<CR><BS><BS>    <Esc>f;a<CR><BS><BS><Esc>ZZ

0 comments


#167 Alain Gilbert / alain_gilbert - Score: 49 - 12/30/10 @ 18:55
wwi <Esc>o<Esc>jf{i<CR><Right><CR>    <Esc>f;a<CR><BS><BS>    <Esc>f;a<CR><BS><BS><Esc>ZZ

0 comments


#168 Brad / bjjwillis - Score: 50 - 12/30/10 @ 01:35
o<Esc>:%s/</ </|%s/}/<C-V><CR>&/|%s/{/<C-V><CR>{<C-V><CR>/|%s/;/&<C-V><CR><CR>V<Up>>ZZ

0 comments


#169 solsTiCe d'Hiver / solstice_dhiver - Score: 50 - 12/30/10 @ 17:56
fw<Esc>f<i <Esc>A<CR><Esc><Down>f{i<CR><Right><CR><Esc>f;a<CR><Esc>f;a<CR><Esc><Up><C-V><Up>I    <Esc>:wq<CR>

0 comments


#170 Timothy Hahn / timyhahn - Score: 50 - 04/20/12 @ 03:49
/<<CR>i <Esc>o<Esc>/{<CR>i<CR><Right><CR><BS><Esc>/;<CR><Right>i<CR>a}<BS><BS><Esc>$i<CR><Up>    <Up><Left><Left><Left><Left>    <Esc>:wq<CR>

0 comments


#171 Phil / phil30075 - Score: 51 - 12/29/10 @ 05:27
:%s/;/;\r/g|%s/){/)\r{\r/g|%s/</ </|s/>/>\r<CR><CR>k7==ZZ

0 comments


#172 drio / drio - Score: 52 - 01/01/11 @ 01:46
f<i <Esc>o<Esc>jf{i<CR><Esc>li<CR><Esc>f;li<CR><Esc>f}i<CR><Esc>kxkx<Esc>i    <Esc>j<Esc>0<Esc>i    <Esc>:x<CR>

0 comments


#173 FAKECAMGRAY / FAKECAMGRAY - Score: 53 - 11/28/11 @ 00:26
fea <Esc>oj<BS><Esc>jf)a<CR><Right><CR><Esc>f;<Esc>a<CR><Esc>f;a<CR><Up><Left><Up><Down>x<BS><Esc>xi    <Up><Esc>xi    <Esc>:wq<CR>

0 comments


#174 Arjen Schat / arjenschat - Score: 79 - 12/29/10 @ 14:50
f<i <Esc><Down>0i<CR>k{<BS><BS><Esc>k{<Down><Down>k<Down>f{i<CR><Right><CR>    f2<BS><BS><Esc>f2r<Esc>frfri<CR>    <Esc>$i<CR><Esc>:wq<CR>

0 comments


#175 Xin Xie / xxie24 - Score: 96 - 12/31/10 @ 01:19
/<<CR>i <Esc>:/<BS><BS>/<Esc>ko/<BS><Esc>/{i<BS><CR>i<CR>l<BS><Esc>li<CR>4<BS><Esc>4i <Esc>/re<CR>i<CR><Esc>lhhhdwi4<BS><Esc>4i <Esc>/}<CR>i<CR><Esc>hhhhhhhhhhhdw<Esc>:wq<CR>

0 comments


#176 Frank Hui / frankhui - Score: 126 - 12/29/10 @ 06:39
:1,$ s/{/{\t/g<CR>:1,$ s/;/;\r\t/g<CR>:1,$ s/>\n/>\r\r/<CR>:1,$ s/{/\r{\r/<CR>:1,$ s/}/\r}\r/<CR><Esc>ddkddkk:1,$ s/\t/    /g<CR>:1,$ s/</ </<CR>:w<CR>:q<CR>

0 comments


Created by: josh_triplett

176 active golfers, 458 entries

Leaderboard (lowest score wins):
23
#1 - Urtica dioica / udioica

01/11/2014 at 06:55AM

23
#2 - John Braxler / braxler

12/22/2014 at 02:36PM

25
#3 - Renat Aksitov / Korvin79

02/15/2012 at 12:27PM

25
#4 - drupalovereasy / drupalovereasy

04/29/2012 at 09:15AM

25
#5 - Charles Gordon / liberalbias

08/26/2012 at 05:13PM

25
#6 - tmr / tmr314

09/05/2012 at 05:09PM

25
#7 - Hubba / HubbaBubbaFett

12/13/2012 at 09:44PM

25
#8 - xavier kt / xav_kt

02/05/2013 at 12:08AM

25
#9 - Petro Тrouq / zulolosi

07/21/2013 at 12:48AM

25
#10 - Yann Moisan / YannMoisan

01/04/2014 at 12:00AM

25
#11 - vimgolf copycat / vimgolf_copycat

03/08/2014 at 03:32PM

25
#12 - david hu / chin33z

12/21/2014 at 05:03AM

25
#13 - BartJanssen / BartJanssen

03/15/2015 at 11:04PM

25
#14 - Melvin Cheung / MelvinCheung

05/25/2017 at 06:49AM

25
#15 - Turkey Man / lvturkeyman

11/27/2017 at 04:20PM

25
#16 - DHM / DHM29978992

05/15/2018 at 02:16AM

26
#17 - Balkoth / _Balkoth_

01/08/2011 at 05:35PM

26
#18 - Federico Galassi / federicogalassi

01/31/2011 at 12:49AM

26
#19 - vg / vimgolfer

02/26/2011 at 12:58PM

26
#20 - Justin Love / wondible

06/13/2011 at 12:54AM

26
#21 - Hu Junfeng / junfeng

07/17/2011 at 11:50AM

26
#22 - Andrey Ivanov / Bytamine

08/11/2011 at 10:45AM

26
#23 - p0ckets / p0ckets

10/07/2011 at 09:23PM

26
#24 - William Dunand / wdunand

12/05/2011 at 04:00AM

26
#25 - Zeh Rizzatti / zehrizzatti

02/08/2012 at 04:46AM

26
#26 - Rod Knowlton / codelahoma

05/27/2012 at 03:32AM

26
#27 - Chris Brown / engineercyb

07/13/2012 at 04:36PM

26
#28 - Kerson Hsiao / KersonHsiao

08/10/2012 at 09:47AM

26
#29 - Jon Krause / jkrause314

11/20/2015 at 07:45AM

27
#30 - Wei Dai / clvv42

12/29/2010 at 08:46AM