3 /// Sketch -- a tutorial Antony Scriven 2003-11-24
8 +---------------------+-----------------------------------------+
10 | ----------------- | ------------------------------------- |
13 | Key-+ | | | Normal mode Visual block |
15 +---------------------+-----------------------------------------+
16 | Lines L c | - or + Transparent box/line |
18 | 2 L c | > < ^ v Box/line with arrow |
20 | S L c | Round/square Opaque box/line |
21 |- - - - - - - - - - -|- - - - - - - - - - - - - - - - - - - - -|
22 | Paint C L cd | Brush Brush fill |
23 | M L c | . -> : -> # |
24 |- - - - - - - - - - -|- - - - - - - - - - - - - - - - - - - - -|
25 | Select R c | Select Erase |
26 | R d | Select Transparent copy+move |
27 | S R d | Opaque copy+move |
28 |- - - - - - - - - - -|- - - - - - - - - - - - - - - - - - - - -|
29 | Erase C R cd | Eraser |
30 | M R cd | Fat eraser |
31 +---------------------+-----------------------------------------+
33 | ---------------- | ------------------------------------- |
34 | <leader>f | Flood fill (any character) |
35 +---------------------+-----------------------------------------+
40 Sketch is a plugin for Vim. Sketch can help with creating
41 simple drawings and diagrams using the mouse. You need at
42 least a two-button mouse to get the most of this package.
43 The shift and control keys are used to modify the mouse's
44 actions. The alt/meta key is also used but I have avoided
45 it for the most part: I realise that some keyboards don't
46 have this key or it isn't easily accessible.
48 Sketch is most useful for line diagrams. It is useful for
49 drawing boxes, lines, and arrows in a quick and hopefully
50 intuitive way. You can draw freehand by clicking and
51 dragging with the mouse. You can also make a visual
52 selection and fill it with a line or a box. Arrowheads
53 can be added easily; the direction is automatic. An
54 eraser is provided. Also there are three different brush
55 tips for painting or for fills.
60 Sketch requires a vim that can handle mouse input. I have
61 incorporated all the drawing functions into the mouse
62 buttons + modifier keys. So you may struggle with a
63 one-button mouse. Also, double-clicks and triple-clicks
64 are used, so these must be supported.
66 Please bear in mind that I have only tested this plugin
67 on gvim 6.1 on Windows. I am unlikely to test on other
68 platforms any time soon. So bug reports or patches for
69 problems encountered on other systems are welcome.
74 This tutorial involves modifying this file. So you may
75 wish to save your own copy before you start editing, e.g.
79 I haven't included any maps to start the plugin. I feel
80 that each user should define the maps that they see fit.
81 The function to start and stop drawing is called
82 ToggleSketch(). So I have in my vimrc:
84 map <F1> :call ToggleSketch()<CR>
86 You should try something similar. When you start Sketch
87 two things should happen. First, a message should appear
88 in the status line telling you that sketch is turned on.
89 Second, if you don't normally display scrollbars in gvim,
90 these will be turned on for you.
92 Note that Sketch implements buffer-local maps. This means
93 that you need to turn Sketch on/off for each individual
94 buffer you draw in. This is not as convenient as
95 having it work globally on all buffers. I implemented it
96 this way because sometimes my mouse would stray into
97 another buffer make unwanted drawings there.
99 Note however that although I have implemented Sketch with
100 buffer-local maps, it is still possible to accidentally
101 draw in another window. I don't think I can avoid this
102 because of the way that Vim handles mouse actions. But
103 the buffer-local maps keep any drawing to a minimum
104 (hopefully just one character). So either make sure that
105 only one window is open, or be careful!
107 Final warning: don't try to size the window by dragging
108 the status line while Sketch is turned on. You will just
109 end up drawing instead. Any fixes for this are most
110 welcome. And don't forget, you can always undo.
114 Throughout this tutorial bear the following in mind. The
115 left mouse button is used for drawing. The right mouse
116 button is used for selecting and erasing.
119 Tip: Get into the habit of 1. turning Sketch on,
120 2. drawing your diagrams, 3. immediately turning
124 -- Freehand line drawing
126 Turn sketch on. To draw a line like this:
127 +-------------------------------------------------------+
129 | -------------------- |
131 +-------------------------------------------------------+
132 simply click with the left mouse button and drag. Here's
133 some space for you to try it. All line drawing is done
134 with the left mouse button. Try it out.
135 +-------------------------------------------------------+
139 +-------------------------------------------------------+
141 +-------------------------------------------------------+
147 +-------------------------------------------------------+
148 Sketch automatically selects a `-' or a `|' depending on
149 the direction you are drawing in. Corners automatically
150 become a cross, as do intersections:
151 +-------------------------------------------------------+
154 | ----+------+----+----+ |
157 +-------------------------------------------------------+
158 Now try just a single click.
159 +-------------------------------------------------------+
163 +-------------------------------------------------------+
164 Note that it is a horizontal line. When you first click,
165 Sketch can't know which direction you are going in. It
166 assumes horizontal. If you actually move vertically, it
167 will correct this initial `-' to a `|'. But what if you
168 really want just a single `|'? This is pretty rare, but I
169 have provided for this. Use a triple-click.
170 +-------------------------------------------------------+
174 +-------------------------------------------------------+
175 Note that if you single-click on an existing character it
177 +-------------------------------------------------------+
179 | Click on these: - | |
180 | They will become: + + |
182 +-------------------------------------------------------+
183 It is often useful to be able to draw arrows. The
184 direction is automatically selected for you. You use a
185 double-click to do this.
186 +-------------------------------------------------------+
191 | Click Double-click |
192 +-------------------------------------------------------+
193 (To select the arrowhead direction without drawing a
194 line, see the section on erasing below.)
199 To paint, you need to hold down the control key while
200 using the left mouse button. The current brush tip is
201 displayed in the command line: [.] or [:] or [#].
202 (Sometimes you can't see it, but I try to display it as
203 much as possible.) If you want to change the brush tip,
204 hold down the meta/alt key and click the left mouse
206 +-------------------------------------------------------+
207 | Ctrl+LeftMouse Meta+LeftMouse, Meta+LeftMouse, |
208 | Ctrl+LeftMouse Ctrl+LeftMouse |
210 | ... .. ::::::::: ########## |
211 | . .. :: ::: ########## |
212 | . .. ::: ### #### |
213 | ...... :::: ###### |
214 | .. :::::: ####### |
216 | . .. :: ::: ### #### |
217 | ... ... ::: ::: ############ |
218 | ..... ::::::: ########## |
219 +-------------------------------------------------------+
221 +-------------------------------------------------------+
222 | Ctrl+LeftMouse Meta+LeftMouse, Meta+LeftMouse, |
223 | Ctrl+LeftMouse Ctrl+LeftMouse |
242 +-------------------------------------------------------+
247 This uses the right mouse button. Don't use just a single
248 rightclick, I'll show you that in the next section. To
249 erase one character, use Control+RightMouse. For a fatter
250 erase, drag with Meta+Rightmouse.
251 +-------------------------------------------------------+
252 | Ctrl+RightMouse Meta+RightMouse |
253 | ####################### ####################### |
254 | ####################### ##### #### |
255 | #### ##### ##### #### |
256 | ################# ##### ##### #### |
257 | #### ##### ############# #### |
258 | #### ################## ######### #### |
259 | #### ################## ####### #### |
260 | #### ###### ####### ####### |
261 | ####################### ####################### |
262 +-------------------------------------------------------+
264 +-------------------------------------------------------+
265 | Ctrl+RightMouse Meta+RightMouse |
266 | ####################### ####################### |
267 | ####################### ####################### |
268 | ####################### ####################### |
269 | ####################### ####################### |
270 | ####################### ####################### |
271 | ####################### ####################### |
272 | ####################### ####################### |
273 | ####################### ####################### |
274 | ####################### ####################### |
275 +-------------------------------------------------------+
276 (If you need to move the cursor out of the way of a
277 drawing, I recommend using Ctrl+RightMouse.)
279 Tip: to select the direction of an arrowhead without
280 drawing a line, you can use the eraser to drag a
281 direction with Control+RightMouse.
283 Tip: Need to make more room for your diagram? Jump to the
284 end of this file (use G) for an example, then use
285 Ctrl-O to jump back here.
288 -- Selection: erasing, boxes, lines, fills
290 Like erasing, this uses the right mouse button. Click and
291 drag to get a visual block selection. Then another right
293 +-------------------------------------------------------+
294 | Right drag over the Then rightclick. |
295 | area marked out by the |
298 | ###################### ####################### |
299 | ##+----------------+## ## ## |
300 | ##|################|## ## ## |
301 | ##|################|## ## ## |
302 | ##|################|## ## ## |
303 | ##|################|## ## ## |
304 | ##|################|## ## ## |
305 | ##|################|## ## ## |
306 | ##+----------------+## ## ## |
307 | ###################### ####################### |
309 +-------------------------------------------------------+
310 This is the most useful way to erase parts of a drawing:
311 Rightdrag, rightclick. To cancel a selection, use <Esc>.
315 You can also use a selection for drawing boxes, lines,
316 and fills. Remember that we drew lines earlier with the
317 leftmouse button, and painted with control+LeftMouse. You
318 can probably guess how these work when a visual block
320 +-------------------------------------------------------+
322 | Select from Then leftclick |
323 | here > >+---------+ |
331 | < to +---------+< |
334 +-------------------------------------------------------+
336 +-------------------------------------------------------+
338 | Select from Then control+leftclick |
339 | here > >........... |
347 | < to ...........< |
350 +-------------------------------------------------------+
351 Boxes are by default transparent. Use shift+leftclick for
353 +-------------------------------------------------------+
354 | Rightdrag, Rightdrag, |
355 | Leftclick Shift+leftclick |
356 | +------------+ +-------------+ |
358 | | +-------------+ | +-------------+ |
361 | +-----|------+ | +------| | |
363 | +-------------+ +-------------+ |
365 +-------------------------------------------------------+
366 Tip: if you want your boxes the same size, make sure you
367 have :set showcmd. The size of your selection will
368 be displayed at the right in the command line.
370 To draw a line, just make sure the selection is one line
371 high, or one line wide.
372 +-------------------------------------------------------+
374 | Select from here > < to here |
375 | Left click >-------------< |
377 +-------------------------------------------------------+
378 When you draw a free hand line, you are drawing through
379 other lines. Intersections became a cross. When you draw
380 a line by dragging a selection, and then left-clicking,
381 the line is above other lines.
382 +-------------------------------------------------------+
383 | Select +------+ then +------+ |
384 | from | | left | | |
385 | here > | | < to here click ------------ |
386 | +------+ +------+ |
387 +-------------------------------------------------------+
388 However, should you want to join a line to a box, for
389 example, this will also work.
390 +-------------------------------------------------------+
392 | +---------+ +---------+ |
395 | +---------+ +----+----+ |
396 | Select from here / | |
401 +-------------------------------------------------------+
402 The line becomes joined to the box.
404 Tip: want to use a character other than `-' or `|'?
405 Highlight as normal then press r<character>
407 Tip: when drawing an arrow using this method you do not
408 need to click to create the line, and then double
409 click to create the arrowhead. You can vis select
410 and then just double click to create the line and
411 the arrowhead in one go.
413 By default, boxes have square corners. This is indicated
414 by the `[Square]' in the command line. If you would like
415 rounded corners, use shift+left-click (similar to meta
416 + left-click to change the paint brush). This is the
418 +-------------------------------------------------------+
420 | With a After Shift + After Shift + |
421 | selection, Left-Click Left-Click, |
422 | Left-Click draw the box draw the box |
424 | +----------+ .----------. +----------+ |
428 | +----------+ '----------' +----------+ |
430 +-------------------------------------------------------+
431 This also effects freehand lines you draw by dragging
432 with the left mouse button.
437 This is classed as a selection, and so it uses the right
438 mouse button. If you right drag on a highlighted region,
439 it is copied, and you can move the copy with the mouse.
440 +-------------------------------------------------------+
442 | +--------------------+ |
446 | +--------------------+ |
449 | Highlight the square, then right drag until |
450 | the cursor is where the arrow indicates. |
452 | +--------------------+ |
454 | | --->+--------------------+ |
456 | +--------------|-----+ ---> | |
458 | +--------------------+ |
459 +-------------------------------------------------------+
460 Note that the selection is transparent by default. Use
461 Shift + RightDrag to get an opaque selection. This is
462 similar to the way that Shift + LeftClick draws an opaque
463 box. I've tried to make the mouse actions consistent in
464 this way. Also note that the mouse is always at the top
465 lefthand corner of the selection.
467 Screen updates when moving transparent objects can either
470 slow, :set lazyredraw
471 or flickery, :set nolazyredraw
473 the choice is yours! (I like to :se lz myself).
475 Because a copy is always created, you can easily use a
476 few shapes as a template to build up a more complicated
477 diagram. I selected a shape from the `Templates' then
478 right-dragged it to form the diagram on the left.
479 +-------------------------------------------------------+
481 | .------------. +-----+ | .------------. |
482 | | |----->| | | | | |
484 | '------------' +-----+ | '------------' |
485 | | | | +-----+ .---. |
487 | +-----+ | | | : : |
488 | .------------. | | | +-----+ \ / |
489 | | |<-----| | | '---' |
490 | | | +-----+ -------------------|
494 | +-----+ .---. .---. |
496 | | |---->: :<--->: : |
499 +-------------------------------------------------------+
500 Tip: naturally you can also select and drag text, so you
501 can move, for example, labels about.
502 Tip: Once a diagram has been started, it is probably
503 quicker to select and drag parts of the diagram
504 about, rather than to keep using your templates box.
506 Using transparent copying, complex diagrams become easy.
507 +-------------------------------------------------------+
509 | .---------. .---------. |
512 | | .---------. | .---------. |
514 | ' |------' | ' |------' | |
516 | \| .---------. \| .---------. |
517 | '------|\ E \ '------|\ F \ |
519 | .---------| .---------.--------| .---------. |
520 | |\ D | | | | C | | | | |
521 | | \ ' |------' |\ ' |------' | |
522 | | .-------\ | \ | .-------\ | \ | |
523 | | | | \| \| | | \| \| |
524 | ' |------' '---------' |------' '---------' |
526 | \| .---------. \| .---------. |
527 | '------|\ H \ '------|\ G \ |
529 | | .---------. | .---------. |
531 | ' |------' | ' |------' | |
534 | '---------' '---------' |
536 +-------------------------------------------------------+
537 To create this diagram:
539 1. Draw a square. This is the back of the box.
541 2. Transparent drag to create the front of the box.
543 3. Manually add the connecting diagonals and rub out
544 lines to make the sides opaque. We now have a box
547 4. Drag copies of this box to make the four boxes at
550 5. Select all four boxes and transparent drag to
551 create the four at the front.
553 6. Manually rub out any lines showing through these
556 Alternatively, you could fill the initial box like this:
562 |##|######|##| Now after you drag the four boxes at
563 '##|------'##| the back to the front, you can search
564 \#|#######\#| for #s and replace with spaces, to
565 \|########\| create the same effect.
568 Sketch isn't meant to be a serious diagramming tool, but
569 if you do need to jot something down in your notes and
570 you don't want to leave the comfort of Vim or plain text
571 format, then it can be useful.
573 Still not convinced of the benefits of this package?
574 Delete all the pictures from the tutorial and give it to
575 someone else to try :-)
578 -- Making more room for your diagram
580 Finally I'll show you how to make some more space for
581 your drawing. Move the cursor here -> <- and then press
582 z<Enter> to make this paragraph at the top of your
583 screen. We are now at the end of the file and you can
584 probably see some tilde's below indicating this. If you
585 try to draw past the end of the file, new lines will
586 automatically be added. So an easy way to make some more
587 room is to erase past the end of the file. Try it, and
588 watch the tildes disappear. Unfortunately, you cannot
589 select a visual block past the end of a file.