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 518360f3fa5db2000200001a

Lookahead and Lookbehind

Look everywhere

Start file
Example for reference:

:%s/\(some\)\@<=thing/one/g
searches for all strings starting with some, then matching thing
changes thing into one
end result: something becomes someone

:%s/\(some\)\@<!thing/one/g
searches for all strings not starting with some, then matching thing
changes thing into one
end result: something is not changed, but everything changes to everyone

:%s/some\(thing\)\@=/every/g
searches for all strings ending with thing, then matching some
changes some into every
end result: something becomes everything

:%s/some\(thing\)\@!/every/g
searches for all strings not ending with thing, then matching some
changes some into every
end result: something is not changed, but someone becomes everyone
End file
Example for reference:

:%s/\(some\)\@<=thing/one/g
searches for all strings starting with some, then matching thing
changes thing into one
end result: someone becomes someone

:%s/\(some\)\@<!thing/one/g
searches for all strings not starting with some, then matching thing
changes thing into one
end result: something is not changed, but everyone changes to everyone

:%s/some\(thing\)\@=/every/g
searches for all strings ending with thing, then matching some
changes some into every
end result: everything becomes everything

:%s/some\(thing\)\@!/every/g
searches for all strings not ending with thing, then matching some
changes some into every
end result: something is not changed, but everyone becomes everyone

View Diff

0a1
> 
6c7
< end result: something becomes someone
---
> end result: someone becomes someone
11c12
< end result: something is not changed, but everything changes to everyone
---
> end result: something is not changed, but everyone changes to everyone
16c17
< end result: something becomes everything
---
> end result: everything becomes everything
21c22
< end result: something is not changed, but someone becomes everyone
---
> end result: something is not changed, but everyone becomes everyone

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 21 remaining solutions by signing in and submitting your own entry
#22 Tim Chase / gumnos - Score: 24 - 05/03/13 @ 15:41
O<Esc>}qa/:<CR>lly$n:<C-R>"<CR>jq3@aZZ

gumnos: What's with the annoying addition of a blank line at the top?

zulolosi: Hello ! It's a mistake, I could delete and recreate ... Sorry !

zulolosi: O<Esc>jqzjjwy$3j:<C-R>"<CR>q3@zZZ -->score 22 (without the blank line, result 19 keystrokes), not bad, what do you think ?

zulolosi: ...and by mistake, we learned a trick, see the @udioica solution ! Best regards !

4 comments

#23 annagrammatica1 / annagrammatica1 - Score: 25 - 05/07/13 @ 03:52
2jqtlxyyuh3j@"jjq@t@t@tZZ

zulolosi: You can have the score 22 with: 2jqtlxyyuh3j@"jjq3@tZZ

zulolosi: I understood, doesn't work my solution with q and u ! Thanks and sorry!

2 comments

#24 Vim Golfer / vimgolfern00b - Score: 26 - 05/07/13 @ 14:53
O<Esc>3jqqlxyyu3j@"2jq@q@q@qZZ

0 comments

#25 Joshua Draper / JoshuaBDraper - Score: 26 - 05/25/13 @ 18:45
O<Esc>3jqqlxyyu3j@"2jq@q@q@qZZ

0 comments

#26 Patrick Mosby / halbtuerke - Score: 27 - 05/07/13 @ 05:02
O<Esc>3jqqlxyyuh3j@"2jq@q@q@qZZ

zulolosi: @q@q@q and 3@q are equivalent ! Best regards

udioica: @zulolosi: Not in this case. When running a macro, commands don't expand the undo branch. That's why you can use u after a macro to undo the whole thing, instead of the million little steps it's made of. Result is, if you use u in a macro, it probably won't do what you want. Note that the U command isn't a "real" undo command; it's just a normal editor command that kinda looks like one. That's why u undoes U and such. U is safe in macros, though it's a bit quirky.

zulolosi: Thanks for the great answer ! Best regards !

3 comments

#27 Adit Cahya Ramadhan / aditcr8 - Score: 27 - 05/16/13 @ 03:38
O<Esc>3jqqlxyyuh3j@"2jq@q@q@qZZ

0 comments

Created by: zulolosi

27 active golfers, 62 entries

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

05/03/2013 at 07:51PM

16
#2 - Abdel Said / abdelsaid

05/07/2013 at 07:10PM

16
#3 - Petro Тrouq / zulolosi

05/09/2013 at 04:57AM

16
#4 - Nathan Bouscal / nbouscal

05/27/2013 at 09:20PM

16
#5 - John Braxler / braxler

08/21/2014 at 05:54PM

17
#6 - Bradd Szonye / bszonye

07/14/2013 at 09:16AM

18
#7 - Kerson Hsiao / KersonHsiao

05/13/2013 at 02:26PM

20
#8 - oliver mueller / marcontwit

05/17/2013 at 07:21PM

20
#9 - Tullio Facchinetti / toolleeo

07/25/2013 at 01:43PM

20
#10 - Steve Tjoa / stevetjoa

07/31/2013 at 06:32PM

20
#11 - brett / brettyukich

09/24/2013 at 11:13PM

20
#12 - Carlos A Henríquez Q / lagunex

01/19/2015 at 10:30AM

20
#13 - pftb12345 / pftb12345

04/29/2015 at 01:02PM

22
#14 - Kai Yuan / kentyuan

05/03/2013 at 09:04PM

22
#15 - Trevor Powell / DoomedBunnies

05/13/2013 at 06:11AM

22
#16 - M8R eonxi21 / eonxi21

05/22/2013 at 09:59AM

22
#17 - Victor Ramirez / virako

05/25/2013 at 11:28PM

22
#18 - Andy Balaam / andybalaam

06/12/2013 at 08:53PM

22
#19 - cj / cj01101

08/21/2013 at 04:08AM

23
#20 - Justin / justinjaffray

05/04/2013 at 07:13PM

23
#21 - James / Dronak

09/27/2014 at 03:12AM

24
#22 - Tim Chase / gumnos

05/03/2013 at 03:41PM

25
#23 - annagrammatica1 / annagrammatica1

05/07/2013 at 03:52AM

26
#24 - Vim Golfer / vimgolfern00b

05/07/2013 at 02:53PM

26
#25 - Joshua Draper / JoshuaBDraper

05/25/2013 at 06:45PM

27
#26 - Patrick Mosby / halbtuerke

05/07/2013 at 05:02AM

27
#27 - Adit Cahya Ramadhan / aditcr8

05/16/2013 at 03:38AM