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 29 remaining solutions by signing in and submitting your own entry
#30 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


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

0 comments


Created by: @zulolosi

31 active golfers, 70 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

16
#6 - Peppa Pig / @PeppaPigSg

07/02/2024 at 01:19AM

17
#7 - Bradd Szonye / @bszonye

07/14/2013 at 09:16AM

17
#8 - vimgolfer / @vimgolfer7

10/21/2019 at 01:54AM

18
#9 - Kerson Hsiao / @KersonHsiao

05/13/2013 at 02:26PM

20
#10 - oliver mueller / @marcontwit

05/17/2013 at 07:21PM

20
#11 - Tullio Facchinetti / @toolleeo

07/25/2013 at 01:43PM

20
#12 - Steve Tjoa / @stevetjoa

07/31/2013 at 06:32PM

20
#13 - brett / @brettyukich

09/24/2013 at 11:13PM

20
#14 - Carlos A Henríquez Q / @lagunex

01/19/2015 at 10:30AM

20
#15 - pftb12345 / @pftb12345

04/29/2015 at 01:02PM

22
#16 - Kai Yuan / @kentyuan

05/03/2013 at 09:04PM

22
#17 - Trevor Powell / @DoomedBunnies

05/13/2013 at 06:11AM

22
#18 - M8R eonxi21 / @eonxi21

05/22/2013 at 09:59AM

22
#19 - Victor Ramirez / @virako

05/25/2013 at 11:28PM

22
#20 - Andy Balaam / @andybalaam

06/12/2013 at 08:53PM

22
#21 - cj / @cj01101

08/21/2013 at 04:08AM

23
#22 - Justin / @justinjaffray

05/04/2013 at 07:13PM

23
#23 - James / @Dronak

09/27/2014 at 03:12AM

24
#24 - Tim Chase / @gumnos

05/03/2013 at 03:41PM

25
#25 - annagrammatica1 / @annagrammatica1

05/07/2013 at 03:52AM

26
#26 - Vim Golfer / @vimgolfern00b

05/07/2013 at 02:53PM

26
#27 - Joshua Draper / @JoshuaBDraper

05/25/2013 at 06:45PM

26
#28 - Alex / @AlexanderHeatl2

05/27/2022 at 05:58PM

26
#29 - nickGPT / @nickandbro

08/28/2024 at 06:38PM

27
#30 - Patrick Mosby / @halbtuerke

05/07/2013 at 05:02AM