" ___ ____ __ _ ___ __ _ _ ____
" Not | |_) | |_ / /` | | | | |_) ( (` | | \ \ / | |_
" |_| \ |_|__ \_\_, \_\_/ |_| \ _)_) |_| \_\/ |_|__
" _ __ __ ___ ___
" | |\/| / /\ / /` | |_) / / \
" |_| | /_/--\ \_\_, |_| \ \_\_/
" ____ _ ___ ___ _ __ __ __ _
" | |_ | | | |_) / / \ | |\ | / /\ / /` / /` | |
" |_| |_| |_|_) \_\_/ |_| \| /_/--\ \_\_, \_\_, |_|
" Preamble: Write out a comment and the first two numbers of the sequence plus
" two trailing spaces. In order to keep track of how many members of the
" sequence we've generated, each time we calculate a number, we'll add another
" space.
let @p = "yiwo\0 numbers of the Fibonacci sequence:\1 1 \"
" Build the "recursive" algorithm
"
" Yank last number on line and paste at end
let @b = "g_yiwg_a \p"
" Yank previous number
let @c = "2geyiw"
" Build macro in "e to increment by value in yank register
let @d = "O\0\\\0\"ey$dd"
" Add by playing back macro "e
let @a = "g_@e"
" Calculate next number in sequence
let @n = "@b@c@d@a"
" Increment counter by adding another space
let @i = "A \"
" Test for end
" 1. Make a copy of the line and remove the spaces at end of line
" 2. Reyank target N
" 3. Build a macro to write a sequence of N 'N' characters
" 4. Yank and run it. Now the copied line contains the Fibonacci sequence
" calculated so far, followed by a series of N Ns.
" 5. Replace entire line with blank characters (this is because when the
" recursive macro ends, we won't get to remove this line. One alternative
" I considered was setting 'nostartofline' and deleting the line with
" `dd` instead of moving up)
" 6. Jump to end of line. Move up onto copied line. Attempt to move right.
" if there are more Ns on the copied line than spaces at the end of the
" real line, then this move will be successful.
" 7. If we get to here, we haven't finished yet. Delete the copied line.
let @t = "yyPg_lD-yiw+O\0AN\\\0y$dd@0Vr +$hlkldd"
" Recursive macro to calculate the requested digits of the sequence
let @f = "@n@i@t@f"
" Set up the final macro
let @q = "@p@f"
" So. To try this out, type the following, now:
"
" :so %
"
" Set all options to default values
set all&
" vim:tw=78:ts=8:norl:nospell:
1,/DELETE_TO_HERE/d
" Place the cursor on any number, and then press @q to run the macro!
" Here's one for you to try: 12