Vim, 22, 18 keystrokes
O <esc>J:h r<cr>lyEZZ<C-v>{@"
Huge credit to @Udioica for coming up with an awesome vim answer that I expanded on. This answer does not contain any asterisks, in hopes of winning the bounty.
Explanation:
Input is typed before the rest of the program. Udioica came up with this awesome trick. Typing <n>O <esc>
will create a pyramid of spaces and one empty line, as long as you have :set autoindent
enabled. This option comes on by default in vim 8 and neovim, though not older versions of vim. Since this also creates an extra line, we use J
to join this line with the next one, which effectively just removes the line below us.
Now at this point, we need to replace all of these spaces with asterisks. If I was not worried about using asterisks in my code, I would just visually select the whole thing <C-v>{
and type r*
, which replaces each character of the selection with an asterisk. But I can't do that.
So we open up the help pages to :h r
. The interesting thing about this is that in the vim-window, this page is displayed as:
r
r{char} Replace the character under the cursor with {char}.
...
With the cursor on the first 'r'. However, the file itself actually contains this text:
*r*
r{char} Replace the character under the cursor with {char}.
...
Pretty convenient. So we move over one character with l
, and yank the text r*
with yE
([y]ank to the [E]nd of this word).
To close this buffer, we use the shortcut to save a file ZZ
. Now, we visually select our spaces, and run the yanked text as if we had typed it by doing @"
. This works because "@" runs the following register as vim-keystrokes, and " is the default register for yanking.