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.
#106 Camilla Krag Jensen / @naxoc - Score: 30 - 07/29/12 @ 05:16
j2I <Esc>j..j.j.j..j...j...j..j.ZZ
0 comments
#107 Gregor Schmidt / @schmidtwisser - Score: 30 - 10/01/12 @ 12:09
:se sw=2<CR>j>>j.2.jj.j.j..j.j.ZZ
0 comments
#108 Ricardo Sisnett / @mrjackinc - Score: 31 - 01/02/11 @ 18:28
jv8j>j>l3jv3j>j>j:%s/\t/ /g<CR>ZZ
0 comments
#109 Thomas Schönwälder / @Masei1988 - Score: 31 - 01/11/11 @ 15:24
j<C-V>GkI <Esc>ji <Esc>3j<C-V>3jI <Esc>j<C-V>jI <Esc>ZZ
0 comments
#110 Francisco Dibar / @frandibar - Score: 31 - 01/12/11 @ 19:55
<CR>i <Esc>.<CR>4.<CR>2.<CR>2.<CR>4.<CR>6.<CR>6.<CR>4.<CR>2.ZZ
0 comments
#111 VitalyBerov / @VitalyBerov - Score: 32 - 12/22/12 @ 17:17
j<C-V>10GqqI <Esc>qj@q6G<C-V>9G@qj@qj@q:wq<CR>
0 comments
#112 Asmund Liseth / @Asmund_L - Score: 33 - 12/31/10 @ 00:51
<Down><C-V>8jI <Esc>ji <Esc>3j<C-V>3jI <Esc>ji <Esc>j.ZZ
0 comments
#113 aimee / @sermoa - Score: 33 - 01/09/11 @ 08: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
#114 eholic / @eholic - Score: 33 - 04/04/11 @ 05:30
j<C-V>8jI <Esc>ji <Esc>3j<C-V>3jI <Esc>j<C-V>jI <Esc>:wq<CR>
0 comments
#115 Charlie Tanksley / @charlietanksley - Score: 33 - 10/13/11 @ 09:13
j<C-V>8jI <Esc>ji <Esc>3j<C-V>3jA <Esc>j<C-V>jI <Esc>:wq<CR>
0 comments
#116 Jordi Romero / @jordiromero - Score: 34 - 12/31/10 @ 07:59
jI <Esc>j..j.j.j..j...j...j..j.:w<CR>:q<CR>
0 comments
#117 Stefan Mai / @iamnafets - Score: 34 - 09/16/11 @ 00:44
:set sw=2<CR><Down>V8<Down>><Down>>><Down><Down><Down>V3<Down>><Down>V<Down>><Esc>:wq<CR>
0 comments
#118 Nicolas Friedli / @NicolasFriedli - Score: 37 - 10/28/12 @ 12:17
<Down>I2<BS> <Esc><Down><Left>..<Left><Down>.<Down>.<Down>..<Down>...<Down>...<Down>..<Down>.<Esc>:wq<CR>
0 comments
#119 Avinash Baliga / @avinashbaliga - Score: 40 - 03/24/11 @ 16:59
jqq0i <Esc>qj2@qj@qj@qj2@qj3@qj3@qj2@qj@qZZ
0 comments
#120 Cássio Marques / @cassiomarques - Score: 41 - 12/30/10 @ 03: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
#121 Lee Marlow / @lmarlow - Score: 42 - 12/31/10 @ 21:48
j<C-V>jjjjjjjjI <Esc>ji <Esc>3ji <Esc>j<C-V>jI <Esc>2ji <Esc>ZZ
0 comments
#122 Ben Lenarts / @benlenarts - Score: 44 - 01/03/11 @ 14:59
:%g/tw/><CR>:%g/fo/>><CR>:%g/si/>>><CR>:%s/\t/ /g<CR>ZZ
0 comments
#123 Dave / @zzdave13 - Score: 44 - 07/31/11 @ 02:16
:g/w/s/^/ <NL>:g/u/s/^/ <NL>:g/x/s/^/ <NL>ZZ
0 comments
#124 Cyril Pascal / @paxal - Score: 50 - 12/30/10 @ 09:57
:2,10s@^@ <CR><Left><C-V><Up><Left>y<Up>P<Up>P<Up>P<Up><Up><Up>i <Esc>ZZ
0 comments
#125 Ragunathan Pattabi / @rpattabi - Score: 52 - 05/10/11 @ 01: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
#126 alex scott / @4l3xsc0tt - Score: 60 - 12/29/10 @ 17:42
<fd-35>:<Up>2,10s/^/ <CR>:3s/^/ <CR>:6,0<BS>9s/^/ <CR>:7,8s^<BS>/^/ <CR>:x<CR>
0 comments
#127 Dylan Beattie / @dylanbeattie - Score: 60 - 12/30/10 @ 07:03
:%s/.*tw/ &/|%<BS>%s/.*ix/ &/|%s/.*fo/ &/<fc-04>|q<BS>wq<NL>
0 comments
#128 KMNK / @kmnk - Score: 69 - 04/24/11 @ 00:39
js2 <Esc>ui <Esc>jhhi <Esc>jhhhhhi <Esc>jI <Esc>jI <Esc>jI <Esc>j.jI <Esc>jI <Esc>;:wq<CR>
0 comments
#129 Amit Kulkarni / @amitkkulkarni - Score: 92 - 12/29/10 @ 23: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
#130 Guillaume Bonnoron / @gbonnoron - Score: 103 - 12/30/10 @ 08: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
#131 Ben Dowling / @coderholic - Score: 120 - 12/31/10 @ 08: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
#132 Andy Brett / @andrewpbrett - Score: 170 - 12/30/10 @ 00: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
VimGolf