I like using barebones Vim to make ASCII art. Vim has a couple of built-in features that I find particularly useful for this task, which I'll document here.
This article is for people who have made ASCII art before and want to see what other tools are out there. If you've never tried making ASCII art before, I recommend you don't read this article! You don't need any of this information to make great ASCII art. Instead, just open up your favorite text editor and start typing. If you're not sure what to make, study the masters and study from life. After that, if you're still curious, then come back and read this.
Vim is not for everyone. I just use it because it's what I know. If you suffer from the same curse, or wish to, then read on!
I recommend having the basics down first (e.g. opening a file, switching
between modes, saving and exiting). If you're new to Vim, you can teach
yourself the basics with vimtutor!
With all those disclaimers out of the way, let's get into it.
When drawing ASCII art, you'll often want to move your cursor to open space. Most text editors will not let you do that unless you fill the buffer with spaces first, and indeed Vim behaves that way by default as well. But do:
:set virtualedit=all
Now you can move your cursor beyond the end of the line. When you insert there, Vim automatically fills in the necessary whitespace on the left. Note that while there doesn't need to be a character present for the cursor to move there, there still has to be be a line there. For more information, see:
:help virtualedit
.--. .--. .--. .--.
|@ @ | |@ @ | |@ @ | |o o |
| | | | | | |~~~ |
'^^^^' '^^^^' '^^^^' '^^^^'
It's also totally valid to not use this feature and just fill the buffer with
spaces at the beginning of your session instead; just know that in Vim it's not
absolutely necessary. If that's what you want to do, Vim can still help: you
can prefix the i and p command with a number to repeat it that many times.
For example, you could insert the space character 42 times:
42i<space><esc>
Then copy the current line and paste it 5 times:
yy5p
In any case, it's important for the cursor to move predictably in the direction you tell it to go, or else some of the other techniques in this guide don't work nearly as well.
Say, for the sake of argument, you have nyan cat:
,----------.
| ` .` `. |
| `. ` `,^----^.
\| . `. | @ w @|
`v-v----"-v-v-"
Suppose you want to draw some squiggles behind nyan cat, but there's not enough space on the left, so you also want to shift nyan cat over to the right. How would you go about that?
Here's one way: Enter Visual block mode with Ctrl+v and select the column behind nyan cat. Then press Shift+i and type some squiggles. You'll notice while you're typing that it looks like you're only inserting on the first line, but that is expected. Only after you press the Escape key will you see that you've actually inserted on all the lines of your selection!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ,----------.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ` .` `. |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | `. ` `,^----^.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\| . `. | @ w @|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ `v-v----"-v-v-"
In this case I actually did:
<ctrl+v>jjjj32I~<esc>
I'll admit this is a pretty contrived example. I usually just use this technique to insert whitespace on multiple lines at once to widen a box, or move something to the right.
Suppose you have this dirty box, and you want to clean it up.
+--------+
| ` ~ |
| * ` .` |
| . ^ . |
+--------+
Here's one way: enter Visual block mode with Ctrl+v. Select the region inside
the box, press r, then press space.
+--------+
| |
| |
| |
+--------+
All done! I often use this technique to erase a section (e.g. if I want to redo
it) without accidentally disturbing another part of the drawing. If I'd pressed
d instead of r, I would have gotten this:
+--------+
||
||
||
+--------+
Sometimes that's desirable, but in this case not what I wanted.
+----+
+----+ | +----+
| | +-| +----+
+----+ +-| |
+----+
In Visual block mode, you can also copy and paste. To copy the current
selection to the clipboard, press y (this puts you back in Normal mode). To
paste, press p or P.
Pasting a block in Normal mode "inserts" it; anything to the right is pushed further to the right.
.----.
| @ @ |
| .--. |
+---------+ .--` <> '--.
| | `--. <> .--'
+---------+ / <> \
/ .--. \
`-' `-'
I usually want to paste "over" what's already there, without shifting anything. To do that, after copying a block, move the cursor somewhere else and try:
1vP
That should have effectively overwritten whatever was there before. To break
that down, 1v is a special variant of v that creates a selection with the
dimensions of your last Visual mode operation. Then, P does two things: it
deletes whatever's selected, then pastes. I recommend P over p because it
doesn't clobber the clipboard, so you can repeat the paste if you want. For
more information on this difference, see:
:help v_P
.----.
| @ @ |
| \__/ |
+---------+ .--` <> '--.
| | `--. <> .--'
+---------+ / <> \
/ .--. \
`-' `-'
Vim allows you to record a sequence of keystrokes and play it back repeatedly.
This can be more powerful than pressing the . key, which can only repeat
single commands.
One simple way to get started with macros is to combine insertion with movement. Let me show you what I mean. In this example, I have this 7x3 tile that I'd like to repeat in a diagonal fashion.
,.-~. +-----+
` _+" --> | 7x3 |
o;.- +-----+
It should tile like so:
+-----+
| 1 |+-----+
+-----+| 2 |+-----+
+-----+| 3 | ...
+-----+
Forgetting about macros for a moment, I would do this by copying the tile using Visual block mode, move the cursor, paste, move the cursor again, paste again. The result:
,.-~.
` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+"
o;.-
In this scenario, it's perfectly reasonable to do without macros, but what if I wanted to paste it 10 or 100 times? Maybe a macro is actually worth trying in that instance.
First I'll copy the tile to the clipboard. Then, I'll position the cursor where I want to start pasting. Then I'll start recording a macro into the 'w' register ('w' is an arbitrary choice, pick whatever register you like):
qw
I'll paste, then move to the next paste location:
1vP<esc>7lj
Finally, I'll stop the recording:
q
Cool, now I have a repeatable macro. To play it back, I just have to do:
@w
And now that it's a macro, I can do it n times:
8@w
,.-~.
` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+" ,.-~.
o;.-` _+"
o;.-
To be honest, I don't use macros a ton when making ASCII art. It's rare that I need to repeat a pattern that many times. Plus, it's easy to program the macro wrong and end up wasting more time than if I'd just done the job manually.
Here's another example:
/\
/\/\/ \
/\ / \
/ \/\ / \ /\ /\
/ \/\ / \/ \/\/\ /\/\/ \
\/\/ \/\ / \
\ /
\/
For this, I used two macros to make my life a bit easier.
The first macro draws a / and moves the cursor up and to the right:
r/kl
The second macro moves the cursor down, draws a \, and moves the cursor to
the right:
jr\l
These macros ensure that my cursor is always positioned at the rightmost end of the line, ready to draw the next segment.
For more info on macros, see:
:help q
.
:`.
: `.
: .:.
:.'\\
` \\
`
By mouse support, I just mean that you can click anywhere in your Vim window to move the cursor there. Useful for drawing pictures! Anyway, you probably knew this; it's usually on by default. If it's off, you can turn it on with:
:set mouse=a
It also works in the terminal! This might surprise you if you haven't used Vim since *checks notes* 1994, or if you're coming from the original vi editor.
In the process of creating your ASCII art, you might lose track of your whitespace. Not a big deal, but if for some reason you want to know what your whitespace looks like, you can ask Vim to make your whitespace visible by doing:
:set list
You should see dollar signs $ demarcating the ends of lines. You can have Vim
visualize other kinds of whitespace as well. See:
:help listchars
When asked, "do you need any special programs or software to make ASCII Art?", the great ASCII artist Joan G. Stark said:
All you need is a text editor with a fixed-width font.
I concur. You don't need any of these tricks or shortcuts to make great ASCII art. If you've decided to make art, a lack of tools isn't going to stop you. In writing this, I don't mean to suggest that these tricks and shortcuts are some kind of secret sauce. That's got to come from within you.