No one:
Really no one:
Me: Last year I wanted to refresh my knowledge with VIM so I did a couple VimGolf
Everyday after work, for a month, I timeboxed 15min to try to make the latest exercise of the VimGolf. Sometimes I failed but I always learned something everyday.
Rural Post #1
Date: 19/10/2020 Challenge: http://www.vimgolf.com/challenges/5f1e0217becb80000692b9c4
Applied a simple macro and delete backwards.
First solution:
qa$bd0jq7@a:wq<CR>
After I tried to learn about running a command multiple times without using macros.
However I did learned about ranges (:help :range) and I was able to find the following solution
:.,$norm $bd0j
Result http://www.vimgolf.com/challenges/5f1e0217becb80000692b9c4#5f8e09bf3866720006e6ddd0
Prepend * to every non-blank line #2
Date: 20/10/2020 Challenge: http://www.vimgolf.com/challenges/5e4dfcccaa2db400090b66c3
I could find a solution with a macro but this time instead, I decide to search for a solution using find and replace. While I could easily append a ‘*’ to the beginning of each line with: `:%s/^/*/` it will add a start also to the empty lines.
My first submission will be the last one but removing the stars that dont have any text afterwards
:%s/\*$//g
I also learnd that I can use the pipe | to concat commands.
:%s/^/*/|:%s/\*$//g
Now what I really want is a way to find all lines with a text and append the star *
:v/^$/norm!I*
':v' - matches the negation of the regex
'^$ - Regex of all empty lines
norm! - Starts the normal input applied to all lines found that are not empty running after certain {commands}
I* - Inserts a start in the beginning of each sentence found
Add semicolons #3
Date: 20/10/2020 Challenge: http://www.vimgolf.com/challenges/5cf62aa56c09760009d6b2f3
After the previous problem this one looks easier but do notice each line has a white space before, but is a matter of checking for a character before a end of line $
:%s/.$/;/
However this will replace the last character and is not what we want, we want to append a ‘;’
So why not user ‘norm’ with A then write the ‘;’
:g/.$/norm!A;
Extra
I did enjoyed this solution
:g/\S/s/$/;/<CR>:x<CR>
:g/\S - is the Range, escaping S to select all lines instead of just the letter 's'
/s/$/; - substitutes the end of each line with ';'
Replaces all lines with a new line that the end is replaced by a ;
Easy modification of ssh config #4
Date: 21/10/2020 Challenge: http://www.vimgolf.com/challenges/5f8fd2f33dc797000ce6d784
This is an hard one for me, I always wondered if I can count and save a number with vim, it would be simple if I knew. So I needed to search for it.
If I know how to increment a value I can simply to a search command and insert it
Today I learned about ‘let’ it will allow me to set a var with a value.
The following vim comamnd will find all the ‘abc’ and replace with xyz_# given # will be an incrementing number starting 1
:let i=1 | g/abc/s//\='xyz_'.i/ | let i=i+1
Knowing this, I need to find a way to match all the lines I need and add the worker# to the end of that line.
For this challenge, `:%s/^host [^m]/` should be enough.
:let i=1 | g/^host [^m]/s/$/\=' worker'.i/ | let i=i+1
I learned something today!
This gave me the first highlight but a terrible score of 56. I think I can at least try to be under 30. But that would be more golfing than learning.
Still, looking at the entry of the person next to me (29 Points @Izmoqwy) I’m already learning some tricks:
i worker0<Esc>ld0qq3j$p<C-A>yawq5@qZZ
- `ZZ` to exit
- `d0` to delete from cursor to start
Resources
- http://vimdoc.sourceforge.net/htmldoc/change.html#CTRL-A
- https://vim.fandom.com/wiki/Making%5Fa%5Flist%5Fof%5Fnumbers
Result http://www.vimgolf.com/challenges/5f8fd2f33dc797000ce6d784#5f908a7e3dc797000ce6d96f
Simple, Practical, and Common #5
Date: 22/10/2020 Challenge: http://www.vimgolf.com/challenges/55b18bbea9c2c30d04000001
This is really simple in terms of movemnt, since the new line we need to add in temp is only difference in numbers increment will take advantage of (increment) numbers, while for the new line of “New text.” We might just need to create 2 ‘o’ (new lines below) The easiest way I found out is yank a empty line and paste it 2 times.
5jyyp$11<C-A>3h<C-A>jyy2j2p
Well… I dont need to yy and paste 2 times, I can simple press enter after writing in a new line, saving clics…
A lesson learn from someone with slightly better score is of Anoop Kumar that is solution was:
6GYpf6R7 11<Esc>3joNew text.<CR><Esc>ZZ
He used
- '6G' goto line 6
- 'Y' instead of yy
- 'f' to find the number 6
- 'R' to start replacing the next caracters and writing 11 instead of <C-A> eleven times
Result: http://www.vimgolf.com/challenges/5f8fd2f33dc797000ce6d784#5f908a7e3dc797000ce6d96f
Box it #6
Date: 24/10/2020 Challenge: http://www.vimgolf.com/challenges/5c742a5a50bdf70006d43280
Repeating a insertion of a character is simple but to determine how many they should be is the interessting part. I need to search how to count the number of caracters and save it to reuse. This is my first exercise, knowing the golf challenge can be jsut count by hand.
We can use `:%s///gn` to count the number of characters. Unfortunatelly doesnt work to set in the ‘let i = …’ going to search
One thing I didn’t saw… the word changes from ‘is’ to ‘was’ need to be more carefull and read everything. For this I can use the find ‘f’ and then replace, I want to delete the caracter and write ‘was’
So this is my first attempt
O#<ESC>vy30pjI# <ESC>fsi<delete>wa<ESC>A #<CR><ESC>31p:x
Result: http://www.vimgolf.com/challenges/5c742a5a50bdf70006d43280#5f9457fb4eba6d00065cc909
Satisfy the go Linter #6
Date: 24/10/2020 Challenge: http://www.vimgolf.com/challenges/5f1063aa8361810006e73210
At first look I will try a combination of macro with line change, will need to use ‘P’ to past upwards and ^ to move to beginning of non white characeter
Something I learned with other challengers is to remind to use of ‘’ for code completion on the wrods TODO and Debug
Result: http://www.vimgolf.com/challenges/5f1063aa8361810006e73210#5f9461ab4eba6d00095cc922
One number per line #7
Date: 24/10/2020 Challenge: http://www.vimgolf.com/challenges/56fb2e75ccffcc0009026473
Full disclousure, I learned how to solve this challenge when I was searching for tutorials in youtube and foun the following one: https://www.youtube.com/watch?v=GvRSiY%5FUFSw
This video taught me how to save numbers in the register (same as delete and yank) and that anything separated in an array will be printed out each in one line. The solution presented in the video gives out a score of 14 that is the maximum. Could I do better? I really don’t think so, not even close…
Nevertheless I’m here to learn and so, the video taught me about:
- ‘"=’ to enter something in the register
- ctr-r to add something to the register
- ctr-a to past the selected into the register
Result: N/A
Yo to Hello #8
Date: 26/10/2020 Challenge: http://www.vimgolf.com/challenges/5ed4f6a27d1dd8000c27e2f6
This is a basic one, can I make it to 10 strokes? Well, writing hello is 5 strokes but I can avoid writing the last ‘o’ if I do a replace Y and write. This means using the ’s'
AH! Though it was simple but, I’m adding a new line at the end, so my subission ends up with a last , meanhing a new line.. Interesting. I was completely wrong! The idea was to ADD a new line… So my solution ended up adding a ‘o’ and save but it costed me more keystrokes
sHELL<Esc>o<Esc>:x<CR>
I’ve now learned some new tricks to avoid writing the extra keystrokes, such as the following
sHELL<C-O>o<Esc>ZZ
Extended Shell Script #9
Date: 27/10/2020 Challenge: http://www.vimgolf.com/challenges/5f98332996f92c000c0095e1
This challenges seems to be a mix of duplicating lines and incrementing numbers, while the incremention can be a simple replace to simplify.
Ypp:s/1/2/gjYppf1s2<ESC>jVjyPP3jf6s1<ESC>jf1s2jF6s1
Didn’t notice that some `pcc` turns into `pcg`. So for this I’m thinking in a macro that change in the current line from `pcc`to `pcg`
Ypqa:s/pcc/pcg/g<CR>jqP:s/1/2/g<CR>jYp@af1r2@a
VjYPP2j@af6r1jf1r2@af6r1
Score of 67 not enough. Lets run the macro with a search & pattertn
VjYpqa:s/pcc/pcg/g<CR>jqP:s/1/2/g2j@af1r2@a
VjyP3jf6r1VkyPV2j@akf1r2ZZ
Forgot to change the third line to pcg-2…
Now Ihave the idea of concatenating 2 macros
VjYpqa:s/pcc/pcg/g<CR>jqPqs:s/1/2/g<CR>@aqj@a@s
Vjy2P2j@aqdf6r1qj@s@dZZ
This was harder to replicate than any other XD
Lesson Learned is that there are different outputs for `p` and `P` when pasting multiple lines and that it is nice to concatenate macros.
To improve upon this I might work with editing registers “, but still it was a good learning
Result: 64 http://www.vimgolf.com/challenges/5f98332996f92c000c0095e1#5f988d19b3e7a50006725ae0
Just the middle #10
Date: 28/10/2020 Challenge: http://www.vimgolf.com/challenges/54862fbb3f90ac0002904cf5
Leaving just the lines with number should be a find & replace of lines without numbers. Lets see what I can do with 7 strokes. Knowing 2 are reserved to exit (:x or ZZ)
:v/\d/d<CR>ZZ` - 10 keystroke
v - All lines that does not match
\d - All numbers
d - delete
This solution gives me 10. I might do better. Will a simple and direct solution be better
2D3j3DZZ
Well, this is 8 keystrokes. Submitted!
Q: How can I shorten it? Is there a negation of interval? Well I can try use negative range. Delete all from -3 to line 2.
- Doesnt work, only if there are already lines before.
Q: How about simple range delete?
2D:4,$d<CR>ZZ
Nope.
I decided to look the answers and seems that there is a spam of the following 7 keystroke answer:
)3:wq!<CR>
At first I didn’t understood it, it does work, I tried it. It is smart that it will write the solution and quit So taking it little my little.
) - Jumpts to the next sentence, this means will jumpt to the first line with a number. 3: - Will mark all the next 2 lines with numbers that we want to save, it even shows the folling starting command `:.,.+2` wq! - Will then this file with only the selected content and quit
Result: There are too many responses I can’t find my submission xD
Remove lines containing the word ‘reader’ #11
Date: 29/10/2020 Challenge:http://www.vimgolf.com/challenges/5c264e64e8c64916d7fca650
The goals is to remove the lines with word “reader” seems a find & delete, can I do it in 9 keystores. I did learned the trick of selected only the lines we want and :wq! to save. Seems that this will be the case, will first count how many it will cost if I do a simple one
:%s/reader/d/g<CR>ZZ' - 17 ...
reader - 6 keystores, how can I imporve to only use 3. This means to go back to the basis and simples delete the lines we want This means keep line 1 and 5 delete the rest.
ddjd3djd2dZZ` - 12 keystrokes
Replace pattern with 1,2,3, … on each line #12
Date: 31/10/2020 Challenge: http://www.vimgolf.com/challenges/5ec18a61827ca60009087755
Replacing all $ in each line with an increasing number. This at first looks like a concatenation of macro and copy paste.
Welp, this even with register I cannot solve it, since I took more than 30min I am stopping for now. I leave my notes.
@a - Search for the first $ and replace it by 1 - f$s1 @s - Saves the current number, searches for next $, replaces it by +1 and moves to the right with l - ylf$s��a"0p
Result: N/A
Words in parens #12
Date: 02/10/2020 Challenge: http://www.vimgolf.com/challenges/5192f96ad8df110002000002
All words in parenthesis, looks for a job for search for words and add the parenthises. Let me check my first solution, keystroke
So my idea was to run a command to all words (\w), however I’ve learn that the `g` command will only run it per one occorrence of word in each line. The following solution is not enough
:g/\w/exec "norm i(\<ESC>ea)"
I’ve learned something awesome in the `:help case`. Search groups. See this: https://stackoverflow.com/a/17440830/1199145
So an answer for this problem can be something like:
:%s/\v(\w+)/\(\1\)/g<CR>ZZ
I’m kinda happy with this but 23 keystrokes :(
A HAPPY NEW YEAR 2014 ! #13
Date: 03/11/2020 Challenge: http://www.vimgolf.com/challenges/52c3cb0d9b8634000200000e
Basically to replace END WITH for NEW and increment the 3 of 2013.
2wc2wNEW<Esc><fd-61>2e<C-A>ZZ
Line under headers #14
Date: 04/11/2020 Challenge: http://www.vimgolf.com/challenges/5d7f565deac0df000cfc2154
Interesting challenge since I’ll need to know the amount of characters the word has, after I remove the ## The first idea is after removing with dw the ‘##’ I’l copy the word and paste it under to then apply a search and replace to the line.
qadwYp:s/./-/g<CR>2jq2@aZZ
And again I didn’t noticed that some of the text changes
To -> Are Underline -> Underlined
dwqaYp:s/./-/g<CR>jjqc2wAre<Esc>@adwAd<Esc><fd-61>@a<Esc><fd-61>ZZ
I might be able to improve upon this, but the exercise is done.
Result: 39 http://www.vimgolf.com/challenges/5d7f565deac0df000cfc2154#5fa328eaedf10c000661a80d
Com(m)a Trouble #15
Date: 05/11/2020 Challenge: http://www.vimgolf.com/challenges/5ba020f91abf2d000951055c
At first seems dauting but should be a matter of deleting ’d' and pasting back ‘P’ with some commands.
qalv16ldhPj^q4@a$qahv16hdpjq4@aZZ
33 sure there is more margin for improvement, hope my future me knows better :hug:
Result: 33 http://www.vimgolf.com/challenges/5ba020f91abf2d000951055c#5fa46c78499a6c0006ed2f43
Bad Copy Syntax #16
Date: 06/11/2020 Challenge: http://www.vimgolf.com/challenges/5d3122ace2e18c0006b8bc4d
For this exercise I might be able to use % to navigate and move the last word of the line. Or simply to a nice find & replace.
No success so I will use a combination of macros and movement. Such as % to jump to the second parenthesis.
qa%bdw%lvt,p%%Pqj^@aZZ
https://stackoverflow.com/a/14035803/1199145
I learn with: http://www.vimgolf.com/challenges/5d3122ace2e18c0006b8bc4d#5d3737722001d2000cacd10f
That the + navigates to the begiining of the next line.
Result: 21 http://www.vimgolf.com/challenges/5d3122ace2e18c0006b8bc4d#5fa683f6c0d13b00064918f8 http://www.vimgolf.com/challenges/5d3122ace2e18c0006b8bc4d#5fa685d0c0d13b000c4918f0
HS Final exam vimgolf #17
Date: 09/10/2020 Challenge: http://www.vimgolf.com/challenges/5fa53808a4d481000c3f114d
For this I’ll use a combination of macro with appending to a register. I’ll add the parenteses with
:%s/\d\d/(&), /g - to add parenthesis
`gg` - to move up start macro to collect data and delete lines
qa"Sdwi(<Right><Right>), <Esc><fd-61>v^"Sdddq11@a"spxxZZ
Result: 33 http://www.vimgolf.com/challenges/5fa53808a4d481000c3f114d#5fa9d82bd285680006e41f5b
Swap Number Pair #18
Date: 10/11/2020 Challenge: http://www.vimgolf.com/challenges/5fa95fbdd285680008e41e4b
For me looks like a search for all parenthesis and reversing the contents. With the ‘magic’ search of \v in the regex
:%s/\v(\d+), (\d+)/\2, \1/g<CR>ZZ
Could I do something with registers? Let me thing a bit since this was a fast one to accomplish. Do remember that ‘f’ can go through multiple lines. so I can cycle through all open parenthesis [
Result: 30 http://www.vimgolf.com/challenges/5fa95fbdd285680008e41e4b#5faae3c104a3c800090512cb
Vice versa #19
Date: 11/11/2020 20:00 Challenge: http://www.vimgolf.com/challenges/55bcdc3ef4219f456102374f
Execise is the simple replace places of two words.
:s/\v(b.<kPlus>x)(.<kPlus>)(l.<kPlus>g)/\3\2\1/<CR>ZZ
(5min) The last slash isn’t necessary, could save 1 keystore. How can I improve?
I felt inspired
fbd2wflPd3wFkpZZ
Put a cross in the square #20
Date: 12/11/2020 Challenge: http://www.vimgolf.com/challenges/5fad35a736518b000960caef
Skipping this exercise since I already seen a possible solution but the other participants. I’m happy to learn something, where here the trick is to to use replace ‘r’ and first fill up down, then down up.
Result: N/A
qqjlr\q5@q0qqlr/kq5@qZZ
Applying same text modification in several lines #21
Date: 12/11/2020 Challenge: http://www.vimgolf.com/challenges/5bbb82f969a25f0009541350
Sounds pretty simple, lets see in how many keystrokes i’m able
qadt_f;Xj0q4@aZZ
Wonder how I could improve upon this.
Result: 16
Simple Text Editing with Vim #22
Date: 14/11/2020 Challenge: http://www.vimgolf.com/challenges/4d1a34ccfa85f32065000004
Starting the first ‘#’ copy the line below and replace the one under with it. I might well have a macro starting at #.
qa3jYjVpq2@aZZ
I ended up moving 3j instead of /#
I did now learn something with the other challengers, I could use the ‘|’ together with :g to duplicate lines and delete what is not needed.
:g/v/t.|+d<CR>ZZ
From a Thunderlink to a Markdown lin #23
Date: 17/11/2020 Challenge: http://www.vimgolf.com/challenges/5ed8b30ea3ee880009111013
The idea here is to grab the url and the exit, might as well se if it works with a simple f&s lets see how many keystrokes that is.
:s/\v.*"(.*)".*(7.*)\<.*/[\2](\1)/<CR>ZZ
But i could at least ommit some characters:
:s/\v.*"(.*)".*(7.*)<.*/[\2](\1)<CR>ZZ
Dropped search and replace and tried something different
9l"adi"2lvt<"sdcc[]()<Esc><fd-61>"aP0"spZZ
#24
Date: 18/11/2020 Challenge: http://www.vimgolf.com/challenges/5e3c8d176ea90a00096b2e63
Add parenthesis and wrap each line with quotes. There must be a key to move between non empty lines and then is a matter of creating a macro to add the quotes.
A (<Esc>qaj^D<Esc><fd-61>a""<Esc>Pq4@aj@ao<Esc><BS>ji)<Esc><fd-61>ZZ
Result: 33 http://www.vimgolf.com/challenges/5e3c8d176ea90a00096b2e63#5fb5986222cb8a0006f62377
One to Ten #25
Date: 19/11/2020 Challenge: http://www.vimgolf.com/challenges/5c4d042acfafb4000c9f06c2
Creating one to ten numbers for me is a combination of copying and incrementing with C-a Since I was having some dificulties starting in 1, I think it is easier if I start in 10 and use capitalized P to past up and use together with a macro.
i10<Esc><fd-61>qaYP<C-X>q8@aZZ
This challenged was based on a reddit post, that I took a look after I submitted my result. Learning quite a bit with the first comment https://www.reddit.com/r/vim/comments/ak4it2/generating%5Fnumber%5Fsequence/
Swap values inside brackets#26
Date: 20/11/2020 Challenge: http://www.vimgolf.com/challenges/5b6f0fcba89379000c2328a4
Don’t have much time to think, its friday and 23:39. lets dooo this
2jwldt)14j3kwpldt)11kbbbpZZ
There is clearly room for improvement since I even did a mistake with the `14j` but no time now. I wanted to practice a bit and do one more exercicse
Result: 27 http://www.vimgolf.com/challenges/5b6f0fcba89379000c2328a4
xrandr outputs and dashes #26
Date: 21/11/2020 Challenge: http://www.vimgolf.com/challenges/5ee9ae243a035f000c6141d7
Done without thinkg, there most be room for improving since the top is 12 keystrokes
17 key strokes `qaj3wei-0q11@aZZ` Since I even did a mistak of using `3we` instead of only `3e` There most be a way to run a macro in all lines with out the ‘qa’ and ‘q’.
Looking at other challenged, I leard the following:
j:,$norm 3ei-<CR>ZZ
The comman will run the command in every line. The comman is needed to run in every line and to move to beggining of the line before running the normal command.
:%s/[1-3]/-&/<CR>ZZ
For every number between 1-3 add a dash before it, `&` means the matched texted. Here he didn’t needed the last `/` Also, he could have used `\d` since this command will only run in the first match of each line, saving quite a bit.
Now thanks to all challengers and learning from them, I got the minimum score of 12 with `:%s/\d/-&ZZ`
Result: 12 http://www.vimgolf.com/challenges/5ee9ae243a035f000c6141d7#5fb923cdd552ef000c11fdba
Swap values #26
Date: 23/11/2020 Challenge: http://www.vimgolf.com/challenges/56d70389bbbe462aff01d42a
For this try I will use a register to save a delete text, just because I’m tired and I want to see the result and then, since I have a bit of time, see what I can improve on a second go.
w"adt,f=D"apF,PZZ - 17 keystrokes
Curious that no one with a keystroke similar to mine used one register. Now, how can I improve upon this?
Well I might be able to use the reserved registers for the effect. For example, if I Visual delect and delete, it will replace what is selected with what I delected but save in the ‘yank the removed text, where then I can use ‘P to paste the result! Lets see how many keystrokes this is.
wdt,f=v$pF,PZZ - 14 keystrokes
Notes: I really liked the idea of Cristian http://www.vimgolf.com/challenges/56d70389bbbe462aff01d42a#56d70766bbbe46285507ba37 He uses a mix of auto-complete with search next with * to get to the objective. Saving 1 keystroke in the process. Should have also remembered that E jumps until the end of the sequence of non-blank characters, separated with white space. This might help me. improve my score
Enumerate Bullets #27
Date: 26/11/2020 Challenge: http://www.vimgolf.com/challenges/5fbfabbbfdf6c50009749916 15min challengesgogogogo
Just learned an important lesson: https://stackoverflow.com/questions/13273741/why-does-incrementing-with-ctrl-a-in-vim-take-me-from-07-to-10
Instead of rellying on search forward, I can start from the end and go down the numbering, with a mixture of using ? to search backwards and a macro.
Gs13.<Esc>vbyqa?- <CR>vpvb<C-X>vwyq11@aZZ
This solution however does not add the leading 0 to numbers less than 10
Gs13.<Esc>vbyqa?- <CR>vpvb<C-X>vwyq2@aqs@ai0<Esc><fd-61>q8@sZZ
Result: 44 — Terrible.. :( http://www.vimgolf.com/challenges/5fbfabbbfdf6c50009749916#5fc413bf0575c20009ac31ba
Basic Renumbering #28
Date: 01/12/2020 Challenge:http://www.vimgolf.com/challenges/54595b13128576000257a3c1
Resources used https://unix.stackexchange.com/questions/72051/vim-how-to-increase-each-number-in-visual-block https://vim.fandom.com/wiki/Generating%5Fa%5Fcolumn%5Fof%5Fincreasing%5Fnumbers https://stackoverflow.com/questions/12399572/vim-how-to-insert-in-visual-block-mode
Used a mix of Visual Block with global a nice trick like this:
Select with visual block and 1 g C-A
<C-V>5jld<C-V>5jI00<Esc><fd-61><Esc><fd-61><C-V>5j1g<C-A>ZZ