Skip to content

Commit

Permalink
feat(note-taking): Add venn-nvim (#901)
Browse files Browse the repository at this point in the history
* feat(venn-nvim): Draw ASCII diagrams easily in Neovim

* Use astrocore set_mapping api to set mappings

* refactor(venn-nvim): integrate with AstroCore and improve keymap setup

* docs(venn-nvim): Move repository up

---------

Co-authored-by: Micah Halter <[email protected]>
Co-authored-by: Uzair Aftab <[email protected]>
  • Loading branch information
3 people authored Apr 23, 2024
1 parent 62ab36a commit 6bb14a2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lua/astrocommunity/note-taking/venn-nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# venn.nvim

Draw ASCII diagrams in Neovim with ease.

**Repository:** <https://github.com/jbyuki/venn.nvim>

1. Enable venn mode with `:ToggleVenn`
- note this enable vim virtual edit mode which allows editing anywhere in the window
2. now click any place and write down the texts
3. use visual block [Ctrl-v] mode to wrap around the text and press f to draw the box
4. connect the boxes using HJKL towards the next box to connect

```
┌───┐
┌────────│ A │──────────┐
│ └───┘ │
│ │
▼ ┌───┐ ▼
B───────►│ C │ D
└─┬─┘ │
│ │
┌─┴─┐ │
│ E │◄─────────┘
└───┘
```
43 changes: 43 additions & 0 deletions lua/astrocommunity/note-taking/venn-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
return {
"jbyuki/venn.nvim",
cmd = "VBox",
dependencies = {
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
commands = {
ToggleVenn = {
function()
local mappings = {
n = { -- draw a line on HJKL keystokes
H = "<C-v>h:VBox<CR>",
J = "<C-v>j:VBox<CR>",
K = "<C-v>k:VBox<CR>",
L = "<C-v>l:VBox<CR>",
},
v = { -- draw a box by pressing "f" with visual selection
f = ":VBox<CR>",
},
}
if vim.b.venn_enabled then
vim.opt_local.virtualedit = ""
for mode, map in pairs(mappings) do
for lhs, _ in pairs(map) do
vim.keymap.del(mode, lhs, { buffer = true })
end
end
vim.b.venn_enabled = nil
else
vim.b.venn_enabled = true
vim.opt_local.virtualedit = "all"
require("astrocore").set_mappings(mappings, { buffer = true })
end
vim.notify(("Venn Diagramming Mode: %s"):format(vim.b.venn_enabled and "Enabled" or "Disabled"))
end,
desc = "Toggle venn diagramming mode",
},
},
mappings = { n = { ["<Leader>v"] = { function() vim.cmd.ToggleVenn() end, desc = "Toggle venn diagramming" } } },
},
},
}

0 comments on commit 6bb14a2

Please sign in to comment.