From 6bb14a21ce7c8b2aacfe999a57b6a7a051da2693 Mon Sep 17 00:00:00 2001 From: Ramesh Santhanakrishnan Date: Tue, 23 Apr 2024 05:00:48 -0700 Subject: [PATCH] feat(note-taking): Add venn-nvim (#901) * 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 Co-authored-by: Uzair Aftab --- .../note-taking/venn-nvim/README.md | 25 +++++++++++ .../note-taking/venn-nvim/init.lua | 43 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 lua/astrocommunity/note-taking/venn-nvim/README.md create mode 100644 lua/astrocommunity/note-taking/venn-nvim/init.lua diff --git a/lua/astrocommunity/note-taking/venn-nvim/README.md b/lua/astrocommunity/note-taking/venn-nvim/README.md new file mode 100644 index 000000000..19bf06d0f --- /dev/null +++ b/lua/astrocommunity/note-taking/venn-nvim/README.md @@ -0,0 +1,25 @@ +# venn.nvim + +Draw ASCII diagrams in Neovim with ease. + +**Repository:** + +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 │◄─────────┘ + └───┘ +``` diff --git a/lua/astrocommunity/note-taking/venn-nvim/init.lua b/lua/astrocommunity/note-taking/venn-nvim/init.lua new file mode 100644 index 000000000..7cc77a775 --- /dev/null +++ b/lua/astrocommunity/note-taking/venn-nvim/init.lua @@ -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 = "h:VBox", + J = "j:VBox", + K = "k:VBox", + L = "l:VBox", + }, + v = { -- draw a box by pressing "f" with visual selection + f = ":VBox", + }, + } + 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 = { ["v"] = { function() vim.cmd.ToggleVenn() end, desc = "Toggle venn diagramming" } } }, + }, + }, +}