Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Creating the Vimcasts logo as ASCII art

#10

Run time:

Demonstrating miscellaneous tips and tricks gleaned whilst making an ASCII art version of the VimCasts.org logo. Learn how to duplicate lines, copy and paste with visual block mode, search and replace within a visual selection, and how to use macros.

Shownotes

In this episode, I demonstrate how to make an ASCII art version of the Vimcasts.org logo. Rather than focussing on a single feature, I demonstrate a handful of miscellaneous tips and tricks as they come up in the course of editing the ASCII art.

If you want to practise these commands for yourself, you can download the file that I used to create this episode.

Convert leading spaces to underscores

The command used to convert leading spaces to underscores was: vwr_. This was then recorded as a macro in register ‘a’ as follows:

qavwr_jq

This can then be replayed once with @a, or multiple times by prepending a count, e.g. 8@a.

Copy and paste with visual block mode

Visual block mode is activated with ctrl-v. Using j to select the entire block, you can then ‘yank’ it with y, then paste with p. You can repeat the paste operation as many times as you like with the . (dot) command, and if you go too far, you can pull it back with the u (undo) command.

Duplicating lines

Sometimes the quickest way to create a new line of content is to copy a neighbouring line using it as a starting point. You can quickly duplicate a line in Vim by issuing the command Yp. This places the cursor on the line below where you started. If you want to put the new line above where the cursor started, you could instead use YP.

Search and replace within a visual selection

Vim lets you define a visual selection, then perform search and replace only on the selected range of lines. It’s tempting to think that in visual block mode, a substitution command such as this:

:s/_/ /g

would operate only on the selected block. But Vim considers the range to include entire lines, so the search and replace operation is not limited to the visual block.

The trick here is to modify the search pattern with the flag \%V. This tells Vim to match only within the visual selection. Running this substitution has the desired effect:

:s/\%V_/ /g

further reading

Comments

Level-up your Vim

Training

Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify

Publications

Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..