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

Indentation

Indent each line according to the right number of spaces it needs.

Start file
this line doesn’t have indentation
this line is indented with two spaces
this one has four
this other one has two
this one is indented with two spaces
this line has a four spaces indentation
this line needs six spaces
this line needs six spaces too
this line is back to four spaces
this line is finally indented with two spaces
this final line is not indented
End file
this line doesn’t have indentation
  this line is indented with two spaces
    this one has four
  this other one has two
  this one is indented with two spaces
    this line has a four spaces indentation
      this line needs six spaces
      this line needs six spaces too
    this line is back to four spaces
  this line is finally indented with two spaces
this final line is not indented

View Diff

2,10c2,10
< this line is indented with two spaces
< this one has four
< this other one has two
< this one is indented with two spaces
< this line has a four spaces indentation
< this line needs six spaces
< this line needs six spaces too
< this line is back to four spaces
< this line is finally indented with two spaces
---
>   this line is indented with two spaces
>     this one has four
>   this other one has two
>   this one is indented with two spaces
>     this line has a four spaces indentation
>       this line needs six spaces
>       this line needs six spaces too
>     this line is back to four spaces
>   this line is finally indented with two spaces

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 115 remaining solutions by signing in and submitting your own entry
#116 aimee / sermoa - Score: 33 - 01/09/11 @ 16:03
j9>>:g/u/><CR>:g/x/>><CR>:%s/\t/  /g<CR>ZZ

sermoa: Go down to the second line and indent 9 lines. Look for everything with 'u' which matches 'four' and further indent those lines. Look for everything with 'x' which matches 'six' and indent those two more times. Finally replace all tabs with two spaces.

sermoa: I really like my solution because it's the first time i've used the :g command. I see that you can be less clever and achieve fewer keystrokes, but i'm more interested in learning something new than achieving the highest score.

rpattabi: u, x stuff is nice

3 comments


#117 eholic / eholic - Score: 33 - 04/04/11 @ 12:30
j<C-V>8jI  <Esc>ji  <Esc>3j<C-V>3jI  <Esc>j<C-V>jI  <Esc>:wq<CR>

0 comments


#118 Charlie Tanksley / charlietanksley - Score: 33 - 10/13/11 @ 16:13
j<C-V>8jI  <Esc>ji  <Esc>3j<C-V>3jA  <Esc>j<C-V>jI  <Esc>:wq<CR>

0 comments


#119 Stefan Schmidt / stafue - Score: 33 - 12/06/13 @ 16:42
jqqi  <Esc>+q8@q3gg@@2j@@2@q2k2@q@@ZZ

0 comments


#120 Jordi Romero / jordiromero - Score: 34 - 12/31/10 @ 15:59
jI  <Esc>j..j.j.j..j...j...j..j.:w<CR>:q<CR>

0 comments


#121 Stefan Mai / iamnafets - Score: 34 - 09/16/11 @ 07:44
:set sw=2<CR><Down>V8<Down>><Down>>><Down><Down><Down>V3<Down>><Down>V<Down>><Esc>:wq<CR>

0 comments


#122 Amir Hedayaty / hedayaty - Score: 35 - 12/30/10 @ 12:14
:set et<CR>:g/w/><CR>:g/u/>><CR>:g/x/>>><CR>:x<CR>

0 comments


#123 Bob Corsaro / doki_pen - Score: 35 - 12/30/10 @ 17:11
:se et<CR>j>>j..j.j.j..j...j...j..j.ZZ

0 comments


#124 Nicolas Friedli / NicolasFriedli - Score: 37 - 10/28/12 @ 19:17
<Down>I2<BS>  <Esc><Down><Left>..<Left><Down>.<Down>.<Down>..<Down>...<Down>...<Down>..<Down>.<Esc>:wq<CR>

0 comments


#125 Ben Brown / benofbrown - Score: 38 - 12/30/10 @ 19:09
ji  <Esc>j^..j^.j^.j^..j^...j^...j^..j^.ZZ

0 comments


#126 Heron Medeiros / heronmedeiros - Score: 39 - 04/13/14 @ 02:56
j<C-V>9<CR>kI  <Esc>vlyjp:6<CR>P:7<CR><C-V>jI    <Esc><Esc>:9<CR>P<Esc>:wq<CR>

0 comments


#127 Will Hardy / whrde - Score: 40 - 12/30/10 @ 15:07
j2I <Esc>2j.j.5j./x<CR>6I <Esc>j./ou<CR>4I <Esc>3k.3k.:wq<CR>

0 comments


#128 Avinash Baliga / avinashbaliga - Score: 40 - 03/24/11 @ 23:59
jqq0i  <Esc>qj2@qj@qj@qj2@qj3@qj3@qj2@qj@qZZ

0 comments


#129 Cássio Marques / cassiomarques - Score: 41 - 12/30/10 @ 11:50
j<C-V>8jc  t<Esc>j<C-V>6jc  t<Esc>:7<CR><C-V>jc  t<Esc>:4<CR>h<C-V>hjx<Esc>:wq<CR>

0 comments


#130 Lee Marlow / lmarlow - Score: 42 - 01/01/11 @ 05:48
j<C-V>jjjjjjjjI  <Esc>ji  <Esc>3ji  <Esc>j<C-V>jI    <Esc>2ji  <Esc>ZZ

0 comments


#131 Ben Lenarts / benlenarts - Score: 44 - 01/03/11 @ 22:59
:%g/tw/><CR>:%g/fo/>><CR>:%g/si/>>><CR>:%s/\t/  /g<CR>ZZ

0 comments


#132 Dave / zzdave13 - Score: 44 - 07/31/11 @ 09:16
:g/w/s/^/  <NL>:g/u/s/^/    <NL>:g/x/s/^/      <NL>ZZ

0 comments


#133 Shaun Robinson / env - Score: 45 - 02/11/14 @ 03:36
j<C-V>8jI  <Esc>ji  <Esc>3j<C-V>3j1I  <Esc>j<C-V>jI  <Esc>:w2<BS><BS>qw!<BS><BS><BS>wq!<CR>

0 comments


#134 Gurukandhamoorthi / Gurukandhamoor1 - Score: 47 - 08/12/17 @ 15:46
:g/tw/>><CR>:g/fo/>>>><CR>:g/ix/>>>>>><CR>:%s/<Tab><Tab><BS>/ /g<CR>ZZ

0 comments


#135 Cyril Pascal / paxal - Score: 50 - 12/30/10 @ 17:57
:2,10s@^@  <CR><Left><C-V><Up><Left>y<Up>P<Up>P<Up>P<Up><Up><Up>i  <Esc>ZZ

0 comments


#136 Ragunathan Pattabi / rpattabi - Score: 52 - 05/10/11 @ 08:40
:g/w/><NL>:g/u/>><NL>:g/x/>>><NL>:%s!\t!  <NL>u:<Up>/g<NL>:<Esc>u:<Up><Left><Left><Del>!<NL>ZZ

0 comments


#137 solsTiCe d'Hiver / solstice_dhiver - Score: 56 - 01/07/14 @ 17:57
:g/two/s/^/  /<CR>:g/four/s/^/    /<CR>:g/six/s/^/      /<CR>:wq<CR>

0 comments


#138 alex scott / 4l3xsc0tt - Score: 60 - 12/30/10 @ 01:42
:<Up>2,10s/^/  <CR>:3s/^/  <CR>:6,0<BS>9s/^/  <CR>:7,8s^<BS>/^/  <CR>:x<CR>

0 comments


#139 Dylan Beattie / dylanbeattie - Score: 60 - 12/30/10 @ 15:03
:%s/.*tw/  &/|%<BS>%s/.*ix/      &/|%s/.*fo/    &/<C->|q<BS>wq<NL>

0 comments


#140 KMNK / kmnk - Score: 69 - 04/24/11 @ 07:39
js2 <Esc>ui  <Esc>jhhi    <Esc>jhhhhhi  <Esc>jI  <Esc>jI    <Esc>jI      <Esc>j.jI    <Esc>jI  <Esc>;:wq<CR>

0 comments


#141 Amit Kulkarni / amitkkulkarni - Score: 92 - 12/30/10 @ 07:30
i<Down>  <Down><Home>    <Down><Home>  <Down><Home>  <Down><Home>    <Down><Home>      <Down><Home>      <Down><Home>    <Down><Home>  <Down><Esc>:wq<CR>

0 comments


#142 Guillaume Bonnoron / gbonnoron - Score: 103 - 12/30/10 @ 16:26
<Down><C-V><Down><Down><Down><Down><Down><Down><Down><Down>I  <Esc><Down><Right><Right>i  <Esc><Down><Left><Down><Right><Left><Down><C-V><Down><Down><Down>.i  <Left>I  <Esc><Right><Right><Down><C-V><Down>I  <Esc>ZZ

0 comments


#143 Ben Dowling / coderholic - Score: 120 - 12/31/10 @ 16:51
:%s/.*two/  \0/g<CR>:<Up><Left><Left><Left><Left>  <Left><Left><Left><Left><Left><BS><BS><BS>four<CR>:<Up><Left><Left><Left><Left>  <Home><Right><Right><Right><Right><Right><Del><Del><Del><Del>six<CR><Esc>:x<CR>

0 comments


#144 Andy Brett / andrewpbrett - Score: 170 - 12/30/10 @ 08:21
j  <Left><Left>i  <Down><Left><Left>    <Down><Left><Left><Left><Left>  <Down><Left><Left>  <Down><Left><Left>    <Down><Down><Up><Left><Left><Left><Left>      <Down><Left><Left><Left><Left><Left><Left>      <Down><Left><Left><Left><Left><Left><Left><Left>    <Down><Left><Left><Left><Left>  <Esc>:wq<CR>

0 comments


Created by: remi

144 active golfers, 405 entries

Leaderboard (lowest score wins):
30
#91 - Joshua Flanagan / jflanagan

12/31/2010 at 11:35PM

30
#92 - Kyle Willmon / kylewillmon

01/01/2011 at 12:36AM

30
#93 - Marcin Ciunelis / martinciu

01/01/2011 at 06:42PM

30
#94 - Stuart Gale / bishboria

01/02/2011 at 07:36PM

30
#95 - Adam Pohorecki / apohorecki

01/04/2011 at 01:24PM

30
#96 - drio / drio

01/07/2011 at 01:04PM

30
#97 - fuck you / jerkassholeface

01/15/2011 at 12:47AM

30
#98 - Andrey A. Ugolnik / andreyugolnik

01/19/2011 at 10:13PM

30
#99 - Oleg Roshupkin / jjjahson

01/21/2011 at 09:39AM

30
#100 - mightyfoo / mightyfoo

05/26/2011 at 02:37PM

30
#101 - (Emile (Swarts)) / EmileSwarts

05/30/2011 at 07:56PM

30
#102 - Lauri Tirkkonen / lotheac

07/01/2011 at 10:06PM

30
#103 - jasper110 / jasper110

09/22/2011 at 09:42AM

30
#104 - William Dunand / wdunand

12/01/2011 at 03:41AM

30
#105 - Camilla Krag Jensen / naxoc

07/29/2012 at 12:16PM

30
#106 - Gregor Schmidt / schmidtwisser

10/01/2012 at 07:09PM

30
#107 - Ram Tamtam / ramtamtamtam

07/02/2014 at 01:28PM

31
#108 - Ricardo Sisnett / mrjackinc

01/03/2011 at 02:28AM

31
#109 - Thomas Schönwälder / Masei1988

01/11/2011 at 11:24PM

31
#110 - Francisco Dibar / frandibar

01/13/2011 at 03:55AM

31
#111 - Oliver Christ / 0liverChrist

02/27/2015 at 03:53PM

32
#112 - VitalyBerov / VitalyBerov

12/23/2012 at 01:17AM

32
#113 - mnx / mnxx

06/13/2014 at 09:44AM

32
#114 - SplinterPie / splinter_pie

05/04/2018 at 11:18AM

33
#115 - Asmund / herrasbe

12/31/2010 at 08:51AM

33
#116 - aimee / sermoa

01/09/2011 at 04:03PM

33
#117 - eholic / eholic

04/04/2011 at 12:30PM

33
#118 - Charlie Tanksley / charlietanksley

10/13/2011 at 04:13PM

33
#119 - Stefan Schmidt / stafue

12/06/2013 at 04:42PM

34
#120 - Jordi Romero / jordiromero

12/31/2010 at 03:59PM