On Sun, 26 Aug 2012, Andy Wokula wrote:

Am 20.08.2012 22:58, schrieb cybrown:
I'm a relatively new VIM user, and I've been playing vimgolf (www.vimgolf.com) to learn new skills. This challenge has a bizarre solution that I don't understand:
http://www.vimgolf.com/challenges/4d1db1b8de2f897c2a00014a

Here's the shortest solution posted:
a.<BS><CR><Esc>[email protected]

First off, I didn't realize @. was a valid macro combination. So, my questions: 1) Is @. any different than .? Why would I want to use one instead of the other?
2) What's going on with this solution? Why does it work but:
a<CR><Esc>[email protected]
doesn't work? What's so special about inserting the dot specifically?

All in all, it's a tricky one; in order to congrat the author I'll give a lengthy explanation :-)

Pretty good explanation.  Two nits:


He implicitly records into the `.' register by typing `.' in Insert mode ("recording" is later stopped with `<Esc>');

He implicitly records into the ". register because he's inserting text with `a'. The ". register "Contains the last inserted text" according to

:help quote.

You can record into ". via i, I, a, A, o, O, and <Insert> (possibly others -- those are the ones I could find quickly).


the dot is not wanted for the line break, so he also hits `<BS>'.
`@.' is executed in Normal mode where the sequence `.<BS><CR>' gets a different meaning. For this special case, `<BS><CR>' is a no-op, so `24@.' executes `.' 24 times in a row, with the intended result.

`<BS><CR>' is <BS> (equivalent to `h', except that 'whichwrap' contains 'b,s' by default, so <BS> wraps over line breaks) followed by <CR> (equivalent to `+'). So <BS><CR> moves up a line (because we're on the first character of the line and it wraps) and down a line. So it's only a "no-op" because it's not performed on the first line of the file (where it would move down by one).

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to