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 58753af0f5ef5c0006000006

Change attribute to getter

Wrap attributes with a getter method.

Start file
function() {
  var a = thing.index < other.attribute;
  var b = thing.index < other.attribute;
  var c = thing.attribute < other.index;
  var d = thing.attribute < other.index;
}
End file
function() {
  var a = thing.get('index') < other.get('attribute');
  var b = thing.get('index') < other.get('attribute');
  var c = thing.get('attribute') < other.get('index');
  var d = thing.get('attribute') < other.get('index');
}

View Diff

2,5c2,5
<   var a = thing.index < other.attribute;
<   var b = thing.index < other.attribute;
<   var c = thing.attribute < other.index;
<   var d = thing.attribute < other.index;
---
>   var a = thing.get('index') < other.get('attribute');
>   var b = thing.get('index') < other.get('attribute');
>   var c = thing.get('attribute') < other.get('index');
>   var d = thing.get('attribute') < other.get('index');

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 63 remaining solutions by signing in and submitting your own entry
#64 Shaw / @Helionitial - Score: 75 - 05/22/22 @ 17:59
:%s/\(thing|<BS>.<BS>\.<BS><BS>|other|<BS>)<BS><BS><BS><BS><BS><BS><BS>\><BS>|other\)\.\(\a*\)/\1.get('\2')/g<<BS><CR>ZZ

0 comments


Created by: @wyne

64 active golfers, 163 entries

Leaderboard (lowest score wins):
39
#61 - Yongjoo Ji / @msrband

01/12/2017 at 01:36AM

47
#62 - Matt Walsh / @wattmalsh

02/08/2017 at 07:21AM

53
#63 - Devin Flake / @flakeman2

05/08/2025 at 06:53PM

75
#64 - Shaw / @Helionitial

05/22/2022 at 05:59PM