7

Here is a simple text-based flowchart I made in Vim for a weblog post:

               [DNS request]
                    |
                    |
                 [Adsuck]
                    |
                    |
                 <block?>
                    |
                   / \
                  /   \
              <YES>    \-> <NO> --> [unbound lookup]
                |
                v
            [noop.py]
                |
                |
        <Have noop script?>
                |
               / \
              /   \
           <YES>   \-> <NO> --> [serve empty GIF]
             |
             v
    [serve noop script]

The problem is, is that it can be rather painstaking; change one thing, and you need to change everything.

Is there anything I can do to make this easier? I don't really care about the above layout of the flowchart as such, as long as it looks flowchart-y it's fine. Flowcharts may also be horizontal as far as I'm concerned, although I prefer vertical like above.

13

Rather than use vim to directly attempt to manipulate ASCII art, why not use vim to edit a file format that defines a graph?

The dot format is a fairly compact way to represent graphs. A rough approximation of the graph you outlined in your example would look like this:

digraph {
  start -> adsuck;
  adsuck -> block;
  block -> noop[label="yes"];
  block -> unbound[label="no"];
  noop -> serve_noop[label="yes"];
  noop -> serve_empty[label="no"];
}

Then you can use Perl's Graph::Easy module to render the graph into a variety of output formats, including ASCII text. It can also produce HTML pages, SVG, PNG, et cetera.

Install Perl if you don't have it, install Graph::Easy (cpanm Graph::Easy, see here for details). This will give you a graph-easy command-line tool. Create yourgraph.dot or whatever (vim has syntax knowledge of the dot format already, and there are also related plugins).

Run graph-easy --as ascii yourgraph.dot output.txt and you'll get something like this:

                      +-------------+
                      |    start    |
                      +-------------+
                        |
                        |
                        v
                      +-------------+
                      |   adsuck    |
                      +-------------+
                        |
                        |
                        v
+------------+  no    +-------------+
|  unbound   | <----- |    block    |
+------------+        +-------------+
                        |
                        | yes
                        v
+------------+  yes   +-------------+
| serve_noop | <----- |    noop     |
+------------+        +-------------+
                        |
                        | no
                        v
                      +-------------+
                      | serve_empty |
                      +-------------+

It's not quite as pretty, but it's a heck of lot easier to edit the dot file than to manipulate all the ASCII art. I found that this article was a pretty nice write-up about building flowcharts with the dot format.

-1

You might try the DrawIt plugin.

DrawIt is a plugin which allows one to draw lines left, right, up, down, and along both slants. Optionally one may "cap" the lines with arrowheads. One may change the horizontal, vertical, slant, and crossing characters to whichever characters one wishes.

  • How do I use this to create & maintain flowcharts? – Martin Tournoij Feb 6 '15 at 19:55
  • Since it is geared toward drawing ASCII art it could lower the amount of pain when you have to refactor. But @JoshPetrie is probably right that using dot would be better. – Quincy Bowers Feb 6 '15 at 20:39
  • 2
    Please read our policy on plugin-recommendation answers and add some detail. A specific example of how to configure the plugin (if necessary) and activate it would be helpful. – 200_success Feb 6 '15 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.