VimScript: 92 characters
I am working at learning Vim and it occurred to me that it could be a neat platform for code golfing. I don't know how to script in Vim that well yet, so any optimization suggestions are appreciated. Note:
^[ does not mean a literal caret next to a literal bracket, but is Vim's way of displaying a literal ESC character in the text.
norm8a ^[a*^[9o^[17a0^[ka ^[15a0^[k2a ^[13a0^[k3a ^[11a0^[k4a ^[9a0^[k5a ^[7a0^[k6a ^[5a0^[k7a ^[3a0^[k8a ^[a0
Here is the output. One of the unique things about this answer is that the output is created in a buffer in Vim (use a
:new buffer). The brackets indicate the final cursor location, which ended up where it did for optimization reasons but I think that is cool:
Updated: 71 characters
Using mapping to reduce number of characters:
map b a0^[k
map c a ^[
Updated: 69 characters
Use punctuation instead of letters for the mapped characters in order to save two space characters.
map. a ^[
Updated: 66 characters
nn ("normal, no remap") for
map to save 2 letters. Also swap final
-. Note that this results in the cursor resting on the star in the final output rather than on the tip-top of the tree right below the star.
nn. a ^[
Updated: 63 characters
Moving/substituting a few more things allows yet another reduction (ignore the
nn, a ^[