How To Create ASCII Drawings in Vim Editor (Draw Boxes, Lines, Ellipses, Arrows Inside Text File)

by SathiyaMoorthy on December 16, 2009

Create ASCII drawings inside Vim EditorYou can create line drawings in Vim editor using the Vim DrawIt! plugin. You can draw flow charts, ER diagrams, or any other diagrams that can be created as line drawing inside a text editor using this plugin.

2 Steps to install drawit.vim

Step 1: Download latest version of the plugin from vim.org

Download the plugin from vim.org

$ cd ~
$ wget -O DrawIt.vba.gz http://www.vim.org/scripts/download_script.php?src_id=8798

Step 2: Install the DrawIt! Vim plugin

$ cd ~
$ vim DrawIt.vba.gz

:so %
:q

5 Powerful Features of Vim Editor DrawIt! Plugin

  • \di will turn on the Drawit! plugin
  • \ds will turn off the Drawit! plugin

Feature 1: Draw as you Navigate inside Vim Editor

From the Vim editor, when you navigate using arrow keys (left, right, up and down) it will draw boxes or lines appropriately as per your navigation.

Following is an example of a simple CPU-Input-Output diagram that was drawn inside Vim editor in just few seconds using only navigation keys to draw the boxes and lines.

Vim Editor DrawIt! Plugin - Draw left, right, up, down and slanting lines

Fig: Text diagram created inside Vim editor in few seconds

Feature 2: Drawing a Box inside Vim Editor (in Visual Mode)

Step 1: Select a region using visual selection.

Draw boxes on a blank filled areas inside a text file

Fig: Visual selection of area to draw a box inside Vim editor

Step 2: Draw box by pressing \b

ASCI Diagram inside a text file using Vim Editor Draw It plugin
Fig: Box diagram created automatically based on selected area inside text file

Feature 3: Drawing Ellipse inside Vim Editor (in Visual Mode)

Step 1: Select a region using visual selection.

Step 2: Draw ellipse by pressing \e

Draw Circle, Rectangle, Triangle or Ellipse inside a Vim Editor Text file
Fig: Ellipse diagram created automatically based on selected area inside text file

Feature 4: Draw Arrows inside Vim Editor

Use the following key strokes to draw the corresponding arrows mentioned below.

  • > left arrow
  • \> fat left arrow
  • < right arrow
  • \< fat arrow
  • ^ up arrow
  • \^ fat up arrow
  • V down arrow
  • \V fat down arrow

Feature 5: Draw Slanting Lines inside Vim Editor

Slanting lines is — front slash and back slash. Use the following key strokes to draw the corresponding slanting lines

  • PageDown – Draw \ move down and right
  • End – Draw / move down and left
  • PageUP – Draw / move up and right
  • Home – Draw \ move up and left

Recommended Reading

Vim 101 Hacks, by Ramesh Natarajan. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to read all available Vim editor tips and tricks. Based on my Vim editor experience, I’ve written Vim 101 Hacks eBook that contains 101 practical examples on various advanced Vim features that will make you fast and productive in the Vim editor. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor.

Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. How To Add Bookmarks Inside Vim Editor
  2. Unix Sed Tutorial: Find and Replace Text Inside a File Using RegEx
  3. 5 Easy Steps to Create a Flowchart Using Dia
  4. Vim Editor: How To Increase or Decrease Date, Time, Roman Number and Ordinals
  5. Vim Editor: How To Setup Most Recently Used Documents Features using MRU Plugin
  

Vim 101 Hacks Book

{ 7 comments… read them below or add one }

1 ged December 16, 2009 at 3:02 am

Thats cool and can be useful when you want to show someone your idea through diagram but there are no MS Visio, Krita or Dia installed on machine and vim is. Thanks a lot, it is quite easy to learn and use.

2 bosha December 16, 2009 at 4:42 am

Thanks man. It’s really useful.

3 Berry December 16, 2009 at 8:58 am

In Feature 5, I think the keys in the number pad match the direction very well. But If I use Notebook, which have no numpad, can I use other keys instead?

4 Tim December 16, 2009 at 9:08 am

With the visual commands, I couldn’t get the \f and \s didn’t work as I expected.

In Vim, is there a way to search all open buffers or a directory and then create a window with a clickable jump list of the results (file and context)?

5 rakesh uv December 18, 2009 at 12:10 am

GOOD one !!

6 Ramesh Natarajan December 19, 2009 at 12:53 pm

@Ged, bosha, rakesh,

I’m glad you liked this article. Thanks for your nice comments.

@Berry,

Yes. You can use those keys (pagedown, end, pageup, home) from the notebook keyboard also.

@Tim,

\s is filling up the space as expected.

Steps:
———
Select specific lines in visual mode,
press \s which will append spaces.

You are right. \f is not working as expected in the visual mode. I’m not sure whether this is a bug in the plugin (or) something else. I’ll do some research on this topic later.

7 Jagdish Chhailkar September 2, 2010 at 1:43 am

I am trying to install DrawIt.vba i.e. drawing tool in vim. I am unable to install it. I am using RHEL 4. In root login i have the file called DrawIt.vba available. I am doing as follows:
# vim DrawIt.vba –> it opens the file in vim
If i issue :so % then i am getting error in line 2 as follows :
Error detected while processing /root/DrawIt.vba:
line 2:
E492: Not an editor command: UseVimball
Hit ENTER or type command to continue
can you please guide how to install this?

Jagdish Chhailkar

Leave a Comment

Previous post:

Next post: