Ruby 1.9 hashes
Rubyists talk about being cutting edge but how many are using 1.9 in production? Time to convert those verbose 1.8 hashes in to symbolic, succinct 1.9 beauties!
Start file
{
:a => 1,
:b => 2,
:c => 3
}
End file
{
a: 1,
b: 2,
c: 3
}
View Diff
2,4c2,4 < :a => 1, < :b => 2, < :c => 3 --- > a: 1, > b: 2, > c: 3
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.
#169 okay zed / @okayzed - Score: 18 - 01/03/11 @ 07:59
jw<C-V>2jdl<C-V>jjllc:<Esc><C-Z>ZZ
0 comments
#170 Vladimir Parfinenko / @cypok - Score: 18 - 01/18/11 @ 21:07
:%s/:<CR>:%s/ =>/:<CR>ZZ
0 comments
#172 Benjamin Sullivan / @benjaminsull - Score: 18 - 12/06/11 @ 07:26
/:<CR>qqxpldt nq2@qZZ
0 comments
#174 vansan / @VinceVansan - Score: 18 - 08/21/12 @ 14:12
jw<C-V>jjXl<C-V>jjllc:<Esc><Esc>ZZ
0 comments
#175 Tyler J. Kuhn / @blackwatertepes - Score: 18 - 08/27/12 @ 09:44
:%s/:<CR>:%s/ =>/:<CR>ZZ
0 comments
#178 Kornél Lugosi / @Coornail - Score: 19 - 01/08/11 @ 02:33
qaj^<Del>ld2wi: <Esc>q2@aZZ
0 comments
#183 Duff OMelia / @duffomelia - Score: 20 - 04/18/11 @ 03:40
jll<C-V>jjdl<C-V>jjllc:<Esc>:wq<CR>
0 comments
#184 IPhone Notiz / @MyIPhoneNotes - Score: 20 - 11/10/11 @ 08:57
jqqwxpl3xj0q2@q:w<CR>ZZ
0 comments
#186 Matt Bridges / @mattdbridges - Score: 20 - 02/02/12 @ 11:29
jqq2lxl3xi:<Esc>j0q2@qZZ
0 comments
#187 Lilibeth De La Cruz / @lilibethdlc - Score: 20 - 03/05/12 @ 19:41
:%s/:\(.\) =>/\1:<CR>ZZ
0 comments
#193 Guillaume Bonnoron / @gbonnoron - Score: 21 - 12/31/10 @ 14:48
:%s/:\(\l\) =>/\1:<CR>ZZ
0 comments
#196 Christopher Brew / @Seph1rothVII - Score: 21 - 01/17/12 @ 14:26
:%s/:\(\a\) =>/\1:<CR>ZZ
0 comments
#197 Nathaniel Barnes / @NathanielBarnes - Score: 21 - 06/20/12 @ 22:48
wxjxjx:%s/ =>/:/g|wq<CR>
0 comments
#198 Daniel Grippi / @danielgrippi - Score: 22 - 12/31/10 @ 11:36
:%s/:\(.\) =>/\1:/g<CR>ZZ
0 comments
#201 Siripong Boonchaiya / @siripong - Score: 23 - 12/31/10 @ 19:31
:%s/\v:(.)\ \=\>/\1:<CR>ZZ
0 comments
#204 Trever Marshall / @dynamic_library - Score: 23 - 10/12/12 @ 13:33
:%s/://<CR>:5<BS>%s/ =>/:/<CR>ZZ
0 comments
#205 aimee / @sermoa - Score: 25 - 01/02/11 @ 12:38
:%s/:\(\w\+\) =>/\1:/g<CR>ZZ
@sermoa: I know i could do it simpler for this particular file, but i wanted to make a generic solution. I think i'll save this as a macro and use it whenever i want to convert hashes on a whole file! :)
@rpattabi: is /g required?
2 comments
#206 Wojciech Pietrzak / @astropanic - Score: 25 - 06/15/11 @ 05:58
:%s/ =>/:/g<CR>:%s/ :/ /g<CR>ZZ
0 comments
#207 Mike Perham / @mperham - Score: 27 - 01/30/11 @ 15:22
:%s/:\(\w*\) =>/\q<BS>1:/<CR>:wq<CR>
0 comments
#208 Joe Auricchio / @jauricchio - Score: 28 - 12/31/10 @ 16:29
:%s/:\(\w\w*\) =>/\1:/g<CR>:wq<CR>
0 comments
#209 Feanor Celebrimbor / @tumbaletaurea - Score: 28 - 06/02/12 @ 13:39
wxjxjxpkhpkhpldwdwuudej.j.ZZ
0 comments
#211 Ed Gibbs / @edward_gibbs - Score: 39 - 10/05/11 @ 08:59
:%s/\s=>//g<CR>x<Up>x<Up>x<Right>:<BS>i:<Down><Left>i:<BS><BS>:<Down><Left>:<Esc>:w<CR>:q<CR>
0 comments
VimGolf