Draftsman.nvim is a Neovim plugin designed to draw ASCII and Unicode diagrams, flowcharts, and boxes effortlessly in Neovim, complete with a helpful sidebar UI to keep track of your tools and settings.
This plugin is inspired by venn.nvim and asciiflow.
ββββββββββββββββββ
β Draw something β
β easily with β
β draftsman.nvim β
βββ¬βββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββ Copy and paste
β using <v> and <p>
β ββββββββββββββββββββββββββββββ βββ βββββ βββββ βββββ
ββββ€ Press <s> to start stroke ββββ β βββββ β β β β β β
β ββββββββββββββββββββββββββββββ βββ βββββ βββββ βββββ
β ββββββββββββββββββββββββββββββ βββ β βββββ βββββ βββββ
ββββ€ Press <a> to draw arrow ββββ β βββΌββ β β β β β β
β ββββββββββββββββββββββββββββββ βββ β βββββ βββββ βββββ
β βββββ βββββ βββββ
β Press <r> to draw rectangle β β β β β β
β βββββββββββββ βββββ βββββ βββββ
β β β Press <m> to move stroke
ββββ€ βββββββββββββββββββββββββββ
β β β β
β βββββββββββββ΄ββββββββββββββββββββββββββ
β
βββDraw with different styles
ββββββ ββββββ +----+
β β β β | |
ββββββ ββββββ +----+
1 2 3
Once you enter Draftsman mode (the default command is DraftmanStart), a sidebar will appear. The sidebar will display available operations and the current status.
Use hjkl to move as usual. Use HJKL (Shift + key) to move faster.
You can move any where on screen.
Draw continuous lines. The plugin handles corners and intersections automatically.
- Press
s/ato start. - Move cursor with
hjkland the line follow cursor's trait. - Press
s/aagain to stop.
Draw rectangles instantly.
- Press
rto start a rectangle. A mark will appear. - Move your cursor to define the size.
- Press
ragain to commit the shape to the canvas.
Press i to insert text. This allows you to type labels over lines without destroying the surrounding structure.
<CR>: Moves down a line (preserving column start).<Esc>: Returns to drawing mode.
Grab a line segment or word and move it.
- Press
mon a line or word. - Move your cursor, and the segment or word moves with you.
- Press
magain to stop moving it.
x: Clears the character under the cursor.<BS>: Just Backspace (clears character to the left).
Draftsman has its own internal clipboard for moving parts of diagrams around.
- Select (
v): Enter visual selection mode. It is use for select rectangular area like press<C-v>in normal mode in vim.- Press
vto start. a Mark will appear. - Move the cursor to choose a rectangular area.
- Yank, delete, or move the chosen area.
- Press
- Move (
m): Cut the selection and move withhjkl. Pressmagain to paste it. - Yank (
y): Copy the selected area. - Delete (
d): Cut/Clear the selected area. - Paste (
p): Paste the clipboard content at the current cursor position.
Switch line style by pressing 1. 2, or 3. Current style will be shown in sidebar. Styles can be customized by configuration. The default styles are
- Style 1: single line.
- Style 2: double line.
- Style 3: ASCII.
Some keys are remapped to behave similarly to their original Vim functions while being better suited for drawing.
| Key | Action |
|---|---|
? |
Toggle Help in Sidebar |
o/O |
Insert a blank line while keeping cursor |
% |
Jump to a connected segment end |
* / # |
Find the next / previous identical stroke |
u |
Undo |
<C-r> |
Redo |
<Esc> |
Exit |
Install using your favorite package manager.
{
"chenyu76/draftsman.nvim",
config = function()
require("draftsman").setup({})
end
}
use({
"chenyu76/draftsman.nvim",
config = function()
require("draftsman").setup()
end,
})Draftsman comes with sensible defaults. You can override the line styles or integration settings by passing a table to the setup function.
Default Configuration:
require("draftsman").setup({
styles = {
[1] = { -- Single Line (Default)
[[ββ¬ββ]],
[[ββΌβ€β]],
[[ββ΄ββ]],
[[βββ ]],
},
[2] = { -- Double Line
[[ββ¦ββ²]],
[[β β¬β£β]],
[[ββ©ββΌ]],
[[βββΊ ]],
},
[3] = { -- ASCII / Classic
[[+++^]],
[[+++|]],
[[+++v]],
[[<-> ]],
},
},
integrations = {
-- Draftsman disables mini.nvim in diagram mode
-- to prevent conflict with drawing mappings.
minisurround = true,
miniai = true,
miniindentscope = true,
minipairs = true,
},
cmd = {
"DraftsmanStart",
"DraftsmanStop",
"DraftsmanToggle",
},
key = {
stroke = "s",
arrow = "a",
rectangle = "r",
move = "m",
insert_text = "i",
},
})- Some wide characters (
\t, CJK, etc.) have strange behaviour.