sponsor Vim development Vim logo Vim Book Ad

DrawX : ASCII and Unicode Art (etch-a-sketch style)

 script karma  Rating 10/6, Downloaded by 1029  Comments, bugs, improvements  Vim wiki

created by
Richard Bentley-Green
 
script type
utility
 
description
NOTE: Version 16/05/21 onwards changes the mapping for entering trace mode from '<leader>0' to '<leader>00'. This is unfortunate, but was necessary in order to accommodate some of the new paste operations

**GUI PASTE BUG** It has come to my attention that there seems to be a bug in some GUI vim versions that means that getregtype() does not return the correct value for the default clipboard register. I have seen this myself with nvim-qt on Windows but I have read reports of it on other GUI versions (not just nvim, but possibly limited to Windows). Anyway, this bug will cause <Leader>\0p (and P) mappings to refuse to work. A way around this seems to be to use another register (specify "<reg> for yank and paste), or you may find that using "0<Leader>0p (or P) works ok to paste the last yank to the default register. Or just use the terminal version of vim :-)

INTRODUCTION

DrawX makes ASCII-art drawing relatively easy. You can draw boxes and lines, and there is support for easily including special characters in your drawings. As well as supporting standard ASCII characters, it also supports a number of different line-drawing styles courtesy of the wider Unicode character set

There are several drawing functions provided;-

1/ Box and ellipse drawing - This allows quick drawing of arbitrary-sized boxes and ellipses, optionally filled with blank space

2/ Tracing - This allows you to move the cursor around and trace a path as you go. Support is provided for joining lines, and placing special characters etc

3/ A flood-fill operation that allows you to fill any arbitrary shape with any character you like

4/ Some special cut and paste operations that are better suited than the standard operations to dealing with ASCII art; they all operate in-place rather than performing any delete or insert operations (basically they are less likely to make a mess of things!). They also provide support for centre cut-out, upside-down and back-to-front pasting

There are several built-in drawing styles. You can also define your own based on any character you like, so you can draw an ellipse with '@' characters if you want

NOTE: I really have no idea what the minimum vim version requirement is to run DrawX and I don't know of a practical way of finding out (I've only used it on v8.2). The best I can suggest is to try it; it will probably work and if it doesn't then let me know and I'll see if I can sort it

*** If you have any suggestions for improving this, then please let me know. If you think it's rubbish then PLEASE let me know why - it's far more useful than just 'voting it down' (which really doesn't help at all). Contact details are in the top of the README file ***

Here is a (rather uninspiring) example. I know it doesn't display very well because it needs a fixed-width font (I have manually jiggled it about a bit to try and improve it), but it's better than nothing and should give you an idea...

    ┌────────────┐          ╔════════════╗
    │Here's a Box                      │          ║          Here's a Box            ║
    └─────┬──────┘          ╚═════╤══════╝
                         │                                                         │
                         ╰────────┬───────╯
                                                         │
                                       ╭╌╌╌╌╌╌╌┴╌╌╌╌╌╌╌╮
                                        ╎  And another Box     ╎
                                        ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯

                       ┏━━━━━┓
                    ■┃◍      ◍┃■
                      ┃ ═══ ┃
                      ┗━━╦━━┛
          ┌──┳━━━╩━━━┳──┐
             │ ┌┨ ┏┅┅┅┓ ┠┐ │
             │ │┃ ┗┅┅┅┛ ┃│ │
             │ │┃ DrawX ┃│ │
             │ │┃             ┃│ │
             └─┘┃          ┃└─┘
                    ┗┳━┳━┳━┳┛
                      ┃ ┃    ┃ ┃
                      ┃ ┃    ┃ ┃
                      ┃ ┃    ┃ ┃
                      ┗━┛   ┗━┛

Copy and paste upside-down and back-to-front....

                                 ┏┓
            ══════┃┃
     ════════┃┃══
┌────────────┐
│┌──┐              ┌──┐│
││       │┌─┐    │      │ │
│└──┘│    │   └──┘│
└────┴─┴─────┘

┌─────┬─┬────┐
│┌──┐    │   │┌──┐│
││       │    └─┘│       ││
│└──┘              └──┘│
└────────────┘
      ══┃┃════════
             ┃┃══════
             ┗┛

 
install details
Just un-tar into ~/.vim/bundle/ as usual and read the README file for config options
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
drawx.tar.gz 15/06/2022 2023-05-02 7.0 Richard Bentley-Green Trivial improvement to error reporting of visually selected operations
drawx.tar.gz 20/04/2022 2022-04-20 7.0 Richard Bentley-Green - Fixed a bug that completely broke DrawX if 'mapleader' was not defined
drawx.tar.gz 17/04/2022 2022-04-18 7.0 Richard Bentley-Green - Added mappings to allow drawing style to be set outside of trace mode; ie, `<leader>\0-`, ``<leader>\0.`, `<leader>\0~`, and `<leader>\0s`, and the 'place special' mapping `<leader>\0+`; it was a bit annoying having to go into trace mode to change the style for box/ellipse drawing and fill operations
- Swapped a few thing around and generally updated the help following recent additions
drawx.tar.gz 16/04/2020 2022-04-16 7.0 Richard Bentley-Green - Added flood fill operation - ref. `<leader\0f` and `f` (in trace mode)
drawx.tar.gz 11/04/2022 2022-04-11 7.0 Richard Bentley-Green I just found out that getcharstr() is a relatively recent addition to vim and will break DrawX if not defined. Have now removed this dependency
drawx.tar.gz 09/04/2022 2022-04-10 7.2 Richard Bentley-Green - Reworked how the trace mode mappings work. This allows a much more robust operation (trace mode won't just drop-out any more when a bad key is pressed). This allows DrawX to detect exactly when it is active, and (more to the point) when the user wants to exit (the way the mappings worked previously meant that a bad key would cause DrawX to silently exit which was really annoying)
- To exit trace mode, the exit key (<esc>) has to be pressed twice to confirm exit. This is to give further protection against accidentally dropping out
- Added undo and redo mappings to trace mode
- Added 'a' and 'A' arrow-placing mappings
- Trivial changes to some status messages
- Minor corrections and changes to the documentation
drawx.tar.gz 05/08/2021 2021-08-05 7.0 Richard Bentley-Green Fixed glaring syntax error that broke 'x' command. Amazed it's taken this long to spot!
drawx.tar.gz 26/05/21 2021-06-04 7.0 Richard Bentley-Green - Made 't' and 'x' operations more 'intelligent' when deciding which character to place (now take account of more variations of character to replace)
- Added operations 'T' and 'X'; these are deliberately 'less intelligent' versions of 't' and 'x'
- Added '!' operation (cancels active direction - useful for T placement - see docs)
drawx.tar.gz 16/05/21 2021-05-16 7.0 Richard Bentley-Green Added cut and paste command and assoc. configuration commands
drawx.tar.gz 02/03/21 2021-03-03 7.0 Richard Bentley-Green Improved 'X' placement (see mapping 'x') and special character placement to prevent them being overwritten (in some cases) when moving away from the place position

drawx.tar.gz 29/01/21 2021-01-29 7.0 Richard Bentley-Green - Added `s` mapping and `DrawXStyle` command to allow setting of arbitrary styles - you can not set a style based on any single character and use it in all drawing functions
- Fixed a bug whereby box drawing function was not drawing dotted lines and curved corners correctly
drawx.tar.gz 26/01/21 2021-01-27 7.0 Richard Bentley-Green - Added ellipse drawing function and associated mappings
- Added fill/no fill option for box drawing; unfortunately, also changed box draw mapping as a result
drawx.tar.gz 03/01/20 2021-01-04 7.0 Richard Bentley-Green - Added 'erase' mode toggle
- Added new mappings to allow moving cursor without tracing (but staying in trace mode)
drawx.tar.gz 30/12/20 2020-12-31 7.0 Richard Bentley-Green - Documented 'cursor keys' and 'exit trace' mappings
- Added ability to change 'exit trace' and `exit menu` keys (both default to `<esc>`) to avoid conflicts with cursor keys
drawx.tar.gz 20/11/20 2020-11-21 7.0 Richard Bentley-Green Initial upload
ip used for rating: 18.226.251.22

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github