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

Python Hello World! Reformatting

A novice Python using prints Hello World! and a pro shows him different way. Using vim to get into pro style from novice, win the challenge.

Start file
#!/usr/bin/python
import sys
a = "Hello World!"
sys.stdout.write(str(a[0]))
sys.stdout.write(str(a[1]))
sys.stdout.write(str(a[2]))
sys.stdout.write(str(a[3]))
sys.stdout.write(str(a[4]))
sys.stdout.write(str(a[5]))
sys.stdout.write(str(a[6]))
sys.stdout.write(str(a[7]))
sys.stdout.write(str(a[8]))
sys.stdout.write(str(a[9]))
sys.stdout.write(str(a[10]))
sys.stdout.write(str(a[11]))
End file
#!/usr/bin/python
import sys
a = "Hello World!"
for i in range(0, len(a)):
  sys.stdout.write(str(a[i]))

View Diff

4,15c4,5
< sys.stdout.write(str(a[0]))
< sys.stdout.write(str(a[1]))
< sys.stdout.write(str(a[2]))
< sys.stdout.write(str(a[3]))
< sys.stdout.write(str(a[4]))
< sys.stdout.write(str(a[5]))
< sys.stdout.write(str(a[6]))
< sys.stdout.write(str(a[7]))
< sys.stdout.write(str(a[8]))
< sys.stdout.write(str(a[9]))
< sys.stdout.write(str(a[10]))
< sys.stdout.write(str(a[11]))
---
> for i in range(0, len(a)):
>   sys.stdout.write(str(a[i]))

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 244 remaining solutions by signing in and submitting your own entry
#245 Nick Bakkegaard / Bakkemand - Score: 46 - 11/26/12 @ 13:25
2jofor i in range(0, len(a)):<Esc>jhhriI  <Esc>j11ddZZ

0 comments


#246 Kuldeep Bora / kuldeep_bora - Score: 46 - 04/21/13 @ 09:48
2jofor i in range(0, len(a)):<Esc>+i  <Esc>f0rij11ddZZ

0 comments


#247 Felix Angerborn / FelixAngerborn - Score: 46 - 09/20/13 @ 20:00
3j11DOfor i in range(0, len(a)):<Esc>jhhxriI  <Esc>:x<CR>

0 comments


#248 Oliver Christ / 0liverChrist - Score: 46 - 09/29/13 @ 18:47
jjofor i in range(0, len(a)):<Esc>+i  <Esc>f0rij11ddZZ

0 comments


#249 LLiseil / lliseil - Score: 46 - 07/15/14 @ 13:42
2<Down>ofor i in range(0, len(a)):<Esc>2+11Di  <Esc>f0ri:x<CR>

0 comments


#250 bratliff / bratliff - Score: 46 - 08/10/14 @ 07:09
4GIfor i in range(0, len(a)):<CR><BS>  <Esc>f0ri<Esc>j11ddZZ

0 comments


#251 Patrick Pitoscia / Patrick03960431 - Score: 46 - 08/17/14 @ 02:48
3jcWfor i in range(0, len(a)):<Esc>j0i  <Esc>f1rijdGZZ

0 comments


#252 Ryan Fitzgerald / rwfitzge - Score: 47 - 12/29/10 @ 11:35
3jOfor i in range(0, len(a)):<Esc>jF0riI  <Esc>jdGZZ

0 comments


#253 Alex B. / SIGKILL - Score: 47 - 12/29/10 @ 13:30
G10dkOfor i in range(0, len(a)):<Right>  <Esc>f0riZZ

0 comments


#254 Joe Hassick / jhassick - Score: 47 - 12/29/10 @ 20:48
3jOfor i in range(0, len(a)):<Esc>2jVGdi<Tab><Esc>f0riZZ

0 comments


#255 Ben Dowling / coderholic - Score: 47 - 12/31/10 @ 20:30
5Gd10<CR>i  <End><Left><Left><Left><BS>i<Up><CR>for i in range(0, len(a)):<Esc>:x<CR>

0 comments


#256 R. P. Fainmen / 4loops - Score: 47 - 01/07/11 @ 20:53
4jdG2I <Esc>:s/0/i<CR>O<BS><BS>for i in range(0, len(a)):<Esc>ZZ

0 comments


#257 ae7o / ae7o - Score: 47 - 04/29/11 @ 21:30
3Gofor i in range(0, len(a)):<Esc>jI  <Esc>f0ri<Esc>jdG:wq<CR>

0 comments


#258 Øystein Walle / oysteinwalle - Score: 47 - 07/12/11 @ 15:25
2jofor i in range(0, len(a)):<CR><Esc>12ddi  <Esc>f12si<Esc>ZZ

0 comments


#259 Tj / yrddy - Score: 47 - 08/19/14 @ 10:38
3jOfor i in range(0, len(a)):<Esc>2jVGd3i  <C-C><C-C>f0riZZ

0 comments


#260 Darkhan / d4rkh4n - Score: 47 - 02/03/16 @ 10:39
5GvGDOfor i in range(0, len(a)):<Esc>wi  <Esc>$hhhri<Esc>ZZ

0 comments


#261 Daniel Dourvaris / dourvaris - Score: 48 - 12/29/10 @ 14:08
/0<CR>ri<CR>11ddifor i in range(0, len(a)):<CR>  <Esc>:wq<CR>

0 comments


#262 Abhinav Gupta / ag90 - Score: 48 - 12/29/10 @ 15:02
3jVGkdOfor i in range(0, len(a)):<Esc>=j/11<CR>cwi<Esc>:wq<CR>

0 comments


#263 Aaron Bull Schaefer / elasticdog - Score: 48 - 12/29/10 @ 16:23
4jd10jOfor i in range(0, len(a)):<Esc>jhhriI  <Esc>ZZ

0 comments


#264 Andrew McDonough / andrewmcdonough - Score: 48 - 12/29/10 @ 18:32
:5<CR>13ddOfor i in range(0, len(a)):<Esc>j>>/0<CR>riZZ

0 comments


#265 Roland Crosby / roooooland - Score: 48 - 12/30/10 @ 08:40
jjofor i in range(0, len(a)):<Esc>j<Left><Left>riI  <Esc>jdGZZ

0 comments


#266 Mikel Ward / mikelward - Score: 48 - 12/30/10 @ 10:01
/0<CR>rij11ddOfor i in range(0, len(a)):<Down><Home>  <Esc>ZZ

0 comments


#267 jonbell17 / jonbell17 - Score: 48 - 12/30/10 @ 20:03
:5,$d<CR>ifor i in range(0, len(a)):<CR>  <Esc>$hhhxii<Esc>:x<CR>

0 comments


#268 drio / drio - Score: 48 - 01/02/11 @ 14:00
3j11ccfor i in range(0, len(a)):<Esc>jhhxri<Esc>0i  <Esc>:x<CR>

0 comments


#269 Jan B. / bracki - Score: 49 - 12/29/10 @ 12:06
4jdGi  <Esc>f0riO<BS>for<Tab>i in range(0, len(a)):<Esc>:x<CR>

0 comments


#270 Lasse Højgaard / lhojgaard - Score: 49 - 12/29/10 @ 12:32
3j11DOfor i in range(0, len(a)):<Esc>jcbi<Esc>I  <Esc>:wq<CR>

0 comments


#271 Drew Neil / nelstrom - Score: 49 - 12/29/10 @ 13:28
4jdG>>f0riO<BS>for i in range(0, len(a)):<Esc><Esc>:wq<CR>

0 comments


#272 Chris Flynn / flynnguy - Score: 49 - 12/29/10 @ 16:14
jjofor i in range(0, len(a)):<Esc>jhhri0i  <Esc>jVGdZZ

0 comments


#273 Andrei Chirila / andrei_chirila - Score: 49 - 12/30/10 @ 16:18
:5,$d<CR>i<CR>  <Up>for i in range(0, len(a)):<Down><BS>i<Esc>ZZ

0 comments


#274 Ryan Kanno / ryankanno - Score: 49 - 01/07/11 @ 07:54
3jifor i in range(0, len(a)):<CR><Esc><<i  <Esc>f0ri<Esc>j%^dGZZ

0 comments


#275 Stephen Gordon / DubsGordon - Score: 49 - 08/01/11 @ 23:28
4GOfor i in range(0, len(a)):<Esc>^ji  <Esc>jhdG/0<CR>cwi<Esc>ZZ

0 comments


#276 Aaron Josephs / aaronjosephs1 - Score: 49 - 05/02/13 @ 02:18
3$A<CR>for i in range(0, len(a)):<Down><Left><Left><BS>i<Esc>0i  <Down><Esc>011ddZZ

0 comments


#277 Aleksander Balicki / alekbalicki - Score: 50 - 12/29/10 @ 14:11
4Gifor i in range(0, len(a)):<CR><Esc>:s/0/i/<CR><Down>dG<Esc>ZZ

0 comments


#278 Dezső Zoltán / zakiazigazi - Score: 50 - 12/29/10 @ 16:04
4GOfor i in range(0, len(a)):<Esc>jhhrij0dGgg=G:wq<CR>

0 comments


#279 Jack Kordas / JackKordas - Score: 50 - 12/29/10 @ 16:08
4jdGi  <Esc>f0riO<BS>for i in range(0, len(a)):<Esc>:wq<CR>

0 comments


#280 Alain Gilbert / alain_gilbert - Score: 50 - 12/30/10 @ 06:09
4GOfor i in range(0, len(a)):<Esc>2<Down>11ddi  <Esc>f0ri:wq<CR>

0 comments


#281 Linus G Thiel / yesbabyyes - Score: 51 - 12/29/10 @ 13:55
3<Down>11ccfor i in range(0, len(a<Esc>A:<Esc>/1<CR>cwi<Esc>I  <Esc>ZZ

0 comments


#282 Boris Barroso / borisb - Score: 51 - 12/29/10 @ 19:27
2jofor i in range(0, len(a)):<Esc>/0<CR>si<Esc>0V>j011D:wq<CR>

0 comments


#283 cracoucax / cracoucax - Score: 51 - 12/30/10 @ 11:00
3jOfor i in range(0, len(a)):<Esc>j==Xi  <Esc>f0rij^^dG:wq<CR>

0 comments


#284 Su. / 0moMi - Score: 51 - 12/31/10 @ 00:16
4Gifor i in range(0, len(a));<BS>:<CR>  <Esc>f0ri<Esc>j11dd:wq<CR>

0 comments


#285 RobertT / techrt2050 - Score: 51 - 09/22/13 @ 05:18
6GdGf1ri2I <Esc>-cfefor i in range<Esc>llcw0, len<Esc>f[d%A:<Esc>ZZ

0 comments


#286 Nacho Barrientos / nachobarrientos - Score: 52 - 12/29/10 @ 12:25
jjjjdGi  <Esc>$hhhrikofor i in range(0, len(a)):<Esc>:wq<CR>

0 comments


#287 Chris Faulkner / bookdarts - Score: 53 - 12/29/10 @ 12:34
GGGGG10dkifor i in range(0, len(a)):<CR><BS>  <Esc>/0<CR>xii<Esc>:x<CR>

0 comments


#288 Jan Kassens / kassens - Score: 53 - 12/29/10 @ 15:30
jjofor i in range(0, len(a)):<Esc>jI  <Esc>f0rijdG:e<BS>wq<CR>

0 comments


#289 Thibault Jouan / tjouan - Score: 53 - 12/29/10 @ 22:17
3t11ddOfor i in range(0, len(a)):<C-C><C-C>t>>f1ciwi<C-C><C-C>:wq<CR>

0 comments


#290 Kishyr Ramdial / kishyr - Score: 54 - 12/29/10 @ 15:44
:4<CR>ifor i in range(0, len(a)):<CR><Tab><Esc>$i<Left><Left><BS>i<Down><Esc>dG:x<CR>

0 comments


#291 Juan C. Muller / juancmuller - Score: 54 - 12/31/10 @ 04:15
:5<CR>VGdI  <Esc>:s/0/i/<BS><CR>O<BS>for i in range(0, len(a)):<Esc>ZZ

0 comments


#292 Justin Knag / justinknag - Score: 54 - 08/28/14 @ 11:28
2jofor i in range(0, len(a)):<C-C><C-C>j0i <C-C><C-C>r0uf0rijVGdi <C-C><C-C>ZZ

0 comments


#293 Alexey Komissarouk / alexeymk - Score: 55 - 12/29/10 @ 13:19
:4<CR>ifor i in range(0, len(a)):<CR><Esc>V:s/0/i<CR><Down>:d40<CR>:wq<CR>

0 comments


#294 smokey42 / smokey42 - Score: 55 - 12/29/10 @ 14:34
3jOfor i in range(0, len(0<BS>a)):<Esc><CR><CR>i  <Esc>f0ri<CR>dGZZ

0 comments


#295 Ed Gibbs / edward_gibbs - Score: 55 - 08/17/11 @ 14:22
:5<CR>V<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down>difor i in range(0, len(a)):<CR><BS>  <Esc>/0<CR>ri<Esc>ZZ

0 comments


#296 Tom Husson / thusson13 - Score: 57 - 12/29/10 @ 16:23
\:4<CR>Ofor i in range(0, len(a)):<Esc><Down>11ddi  <Esc>/1<CR>cwi<Esc>:wq<CR>

0 comments


#297 Pablo Ambrosio / pandres_ - Score: 59 - 12/29/10 @ 17:49
3jOfor i in ragn<BS><BS>nge(0, len(a)):<Esc>jI  <Esc>f0ri<Esc>j11dd:x<CR>

0 comments


#298 Nick Jones / nickj89 - Score: 61 - 12/29/10 @ 12:27
:4<CR>d10<Down>ifor i in range(0, len(a)):<CR><BS><BS><Esc>:%s/11/i/g<CR>:x<CR>

0 comments


#299 David Bengoa / DvdBng - Score: 62 - 12/29/10 @ 13:14
444jdGOfor i in range(0, len(a):<Left>)<Down><Left><C-H>i<Home>  <Esc>:w<CR>:q<CR>

0 comments


#300 Markus Nilsson / markusnilsson - Score: 66 - 12/29/10 @ 16:02
4ggd10dddifor i in range(0, len(a)):<CR><BS>  <Esc>$<Left><Left>i<BS><BS>i<Esc>:wq<CR>

0 comments


#301 digitalparoxysm / digitalparoxysm - Score: 66 - 12/29/10 @ 18:48
jjjvGdi s<Esc>bj^i <Esc>A<Left><Left><Left><C-H><C-H>i<Esc>kofor i in range(0, len(a)):<Esc>:wq<CR>

0 comments


#302 Matty Williams / matty_jwilliams - Score: 66 - 04/26/12 @ 20:03
jjjOifor i<BS><BS><BS><BS><BS><BS>for i in range(0, len(a)):<Esc><Down>i<BS><BS>i]<Esc>$^i  <Esc><Down>11dd<Esc>:wq<CR>

0 comments


#303 Timothy Hahn / timyhahn - Score: 83 - 04/20/12 @ 03:30
4Gd10<BS><Esc>;u<CR>d14<CR>ofor i in range(0, len(a)):<CR><BS>   <BS><BS><BS>  sys.stdout.write(str(a[i]))<Esc>:wq<CR>

0 comments


#304 Trever Marshall / dynamic_library - Score: 83 - 10/12/12 @ 20:49
:4<CR>V}cfor i in range()<Left>0, len()<Left>q<BS>a<Right><Right>/<BS>:<CR><BS>  syst<BS>.stdout.write()<Left>str()<Right><Left><Left>a[]<Right><Left><Left>i<Esc>ZZ

0 comments


#305 Zhao Yao / Lynch8080 - Score: 93 - 12/31/10 @ 17:33
jjj12ddofor i in range()<Esc>i0, len()<Esc>ia<Esc>$a:<CR><BS>  sysy<BS>.stu<BS>dout.write()<Esc>istr()<Esc>ia[]<Esc>ii<Esc>:wq<CR>

0 comments


Created by: Ujjwol

305 active golfers, 792 entries

Leaderboard (lowest score wins):
39
#1 - Turkey Man / lvturkeyman

11/24/2017 at 08:42AM

39
#2 - azzal07 / azzal07

03/08/2018 at 07:22PM

40
#3 - Andrey Ivanov / Bytamine

08/11/2011 at 02:32PM

40
#4 - You-Siang Lin / yslinnctu

11/30/2011 at 12:04PM

40
#5 - Pei-Lun Lee / ypcatw

01/07/2012 at 03:29PM

40
#6 - Renat Aksitov / Korvin79

02/07/2012 at 11:31PM

40
#7 - Zeh Rizzatti / zehrizzatti

02/08/2012 at 05:45PM

40
#8 - Rändöm Tester / mevcar

02/12/2012 at 04:27PM

40
#9 - Rod Knowlton / codelahoma

05/27/2012 at 04:07AM

40
#10 - Conner McDaniel / connermcd

09/19/2012 at 02:09AM

40
#11 - Urtica dioica / udioica

12/13/2012 at 07:48AM

40
#12 - Adam Bell / adamgbell

03/30/2013 at 12:26AM

40
#13 - M8R eonxi21 / eonxi21

05/20/2013 at 06:28PM

40
#14 - Marco Hinz / _mhinz_

05/22/2013 at 09:11AM

40
#15 - Petro Тrouq / zulolosi

07/04/2013 at 09:23PM

40
#16 - Conor Kirkman / conorkirkman

07/18/2013 at 06:48PM

40
#17 - Arturo Escaip / arturoescaip

09/01/2013 at 08:55AM

40
#18 - Andrew O'Neill / AndroidOatmeal

02/19/2014 at 06:33PM

40
#19 - John Braxler / braxler

04/15/2014 at 07:32PM

40
#20 - David Shields / salacio

04/22/2014 at 08:27PM

40
#21 - pftb12345 / pftb12345

04/12/2015 at 09:08AM

40
#22 - JinHwan Choi / jinhwanlazy

03/26/2016 at 06:50AM

40
#23 - Chenut Ludovic / 7Brwa7

04/04/2016 at 12:11PM

40
#24 - Jon Krause / jkrause314

04/11/2016 at 08:46PM

40
#25 - Ameen P / Ameen_P1

06/18/2016 at 10:06AM

40
#26 - sijinyuan / sijinyuan

03/18/2017 at 06:00AM

40
#27 - DHM / DHM29978992

04/30/2018 at 03:33AM

41
#28 - dominique pellé / vimgolfisto

01/01/2011 at 06:02PM

41
#29 - Akira Matsuda / a_matsuda

01/05/2011 at 03:58PM

41
#30 - Wei Dai / clvv42

01/07/2011 at 04:06AM