From a1be6bfbb418a4a78f60ca6976d9c79057c9ef3a Mon Sep 17 00:00:00 2001 From: Ramesh Santhanakrishnan Date: Fri, 19 Apr 2024 20:42:12 -0700 Subject: [PATCH 1/4] feat(venn-nvim): Draw ASCII diagrams easily in Neovim --- .../note-taking/venn-nvim/README.md | 23 +++++++++++ .../note-taking/venn-nvim/init.lua | 39 +++++++++++++++++++ 2 files changed, 62 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..569d9c3ee --- /dev/null +++ b/lua/astrocommunity/note-taking/venn-nvim/README.md @@ -0,0 +1,23 @@ +# venn.nvim + +Draw ASCII diagrams in Neovim with ease. + + 1. Enable venn mode, :lua Toggle_Venn + - 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 │◄─────────┘ + └───┘ + +**Repository:** + 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..15358772c --- /dev/null +++ b/lua/astrocommunity/note-taking/venn-nvim/init.lua @@ -0,0 +1,39 @@ +return { + "jbyuki/venn.nvim", + event = "VeryLazy", + cmd = "VBox", + keys = { + { + "vn", + "lua Toggle_venn()", + { silent = true }, + desc = "Toggle Venn diagram", + }, + }, + config = function() + function _G.Toggle_venn() + local venn_enabled = vim.inspect(vim.b.venn_enabled) + if venn_enabled == "nil" then + vim.notify("enabled Venn mode", "info", { title = "Venn" }) + vim.b.venn_enabled = true + vim.cmd [[setlocal ve=all]] + -- draw a line on HJKL keystokes + vim.api.nvim_buf_set_keymap(0, "n", "J", "j:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "K", "k:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "L", "l:VBox", { noremap = true }) + vim.api.nvim_buf_set_keymap(0, "n", "H", "h:VBox", { noremap = true }) + -- draw a box by pressing "f" with visual selection + vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox", { noremap = true }) + else + vim.notify("disabled Venn mode", "info", { title = "Venn" }) + vim.cmd [[setlocal ve=]] + vim.api.nvim_buf_del_keymap(0, "n", "J") + vim.api.nvim_buf_del_keymap(0, "n", "K") + vim.api.nvim_buf_del_keymap(0, "n", "L") + vim.api.nvim_buf_del_keymap(0, "n", "H") + vim.api.nvim_buf_del_keymap(0, "v", "f") + vim.b.venn_enabled = nil + end + end + end, +} From 339c5d20cfb437e3aebbbf371e9443a72089fd7b Mon Sep 17 00:00:00 2001 From: Ramesh Santhanakrishnan Date: Sat, 20 Apr 2024 12:12:37 -0700 Subject: [PATCH 2/4] Use astrocore set_mapping api to set mappings --- .../note-taking/venn-nvim/init.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lua/astrocommunity/note-taking/venn-nvim/init.lua b/lua/astrocommunity/note-taking/venn-nvim/init.lua index 15358772c..6a358314f 100644 --- a/lua/astrocommunity/note-taking/venn-nvim/init.lua +++ b/lua/astrocommunity/note-taking/venn-nvim/init.lua @@ -17,13 +17,18 @@ return { vim.notify("enabled Venn mode", "info", { title = "Venn" }) vim.b.venn_enabled = true vim.cmd [[setlocal ve=all]] - -- draw a line on HJKL keystokes - vim.api.nvim_buf_set_keymap(0, "n", "J", "j:VBox", { noremap = true }) - vim.api.nvim_buf_set_keymap(0, "n", "K", "k:VBox", { noremap = true }) - vim.api.nvim_buf_set_keymap(0, "n", "L", "l:VBox", { noremap = true }) - vim.api.nvim_buf_set_keymap(0, "n", "H", "h:VBox", { noremap = true }) - -- draw a box by pressing "f" with visual selection - vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox", { noremap = true }) + require("astrocore").set_mappings({ + n = { + ["J"] = "j:VBox", + ["K"] = "k:VBox", + ["L"] = "l:VBox", + ["H"] = "h:VBox", + }, + v = { + -- draw a box by pressing "f" with visual selection + ["f"] = ":VBox", + }, + }, {}) else vim.notify("disabled Venn mode", "info", { title = "Venn" }) vim.cmd [[setlocal ve=]] From 10312b5838e78ac1498a4b1b6bb02b7b11d89d84 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Mon, 22 Apr 2024 12:38:44 -0400 Subject: [PATCH 3/4] refactor(venn-nvim): integrate with AstroCore and improve keymap setup --- .../note-taking/venn-nvim/README.md | 36 ++++----- .../note-taking/venn-nvim/init.lua | 75 +++++++++---------- 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/lua/astrocommunity/note-taking/venn-nvim/README.md b/lua/astrocommunity/note-taking/venn-nvim/README.md index 569d9c3ee..6742cd5b1 100644 --- a/lua/astrocommunity/note-taking/venn-nvim/README.md +++ b/lua/astrocommunity/note-taking/venn-nvim/README.md @@ -2,22 +2,24 @@ Draw ASCII diagrams in Neovim with ease. - 1. Enable venn mode, :lua Toggle_Venn - - 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 │◄─────────┘ - └───┘ +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 -**Repository:** +``` + ┌───┐ + ┌────────│ A │──────────┐ + │ └───┘ │ + │ │ + ▼ ┌───┐ ▼ + B───────►│ C │ D + └─┬─┘ │ + │ │ + ┌─┴─┐ │ + │ E │◄─────────┘ + └───┘ +``` +**Repository:** diff --git a/lua/astrocommunity/note-taking/venn-nvim/init.lua b/lua/astrocommunity/note-taking/venn-nvim/init.lua index 6a358314f..7cc77a775 100644 --- a/lua/astrocommunity/note-taking/venn-nvim/init.lua +++ b/lua/astrocommunity/note-taking/venn-nvim/init.lua @@ -1,44 +1,43 @@ return { "jbyuki/venn.nvim", - event = "VeryLazy", cmd = "VBox", - keys = { - { - "vn", - "lua Toggle_venn()", - { silent = true }, - desc = "Toggle Venn diagram", + 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" } } }, }, }, - config = function() - function _G.Toggle_venn() - local venn_enabled = vim.inspect(vim.b.venn_enabled) - if venn_enabled == "nil" then - vim.notify("enabled Venn mode", "info", { title = "Venn" }) - vim.b.venn_enabled = true - vim.cmd [[setlocal ve=all]] - require("astrocore").set_mappings({ - n = { - ["J"] = "j:VBox", - ["K"] = "k:VBox", - ["L"] = "l:VBox", - ["H"] = "h:VBox", - }, - v = { - -- draw a box by pressing "f" with visual selection - ["f"] = ":VBox", - }, - }, {}) - else - vim.notify("disabled Venn mode", "info", { title = "Venn" }) - vim.cmd [[setlocal ve=]] - vim.api.nvim_buf_del_keymap(0, "n", "J") - vim.api.nvim_buf_del_keymap(0, "n", "K") - vim.api.nvim_buf_del_keymap(0, "n", "L") - vim.api.nvim_buf_del_keymap(0, "n", "H") - vim.api.nvim_buf_del_keymap(0, "v", "f") - vim.b.venn_enabled = nil - end - end - end, } From 31fbe920b989ccadaf2bb6190de263df8d6eb5f4 Mon Sep 17 00:00:00 2001 From: Uzair Aftab Date: Tue, 23 Apr 2024 13:59:31 +0200 Subject: [PATCH 4/4] docs(venn-nvim): Move repository up --- lua/astrocommunity/note-taking/venn-nvim/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/astrocommunity/note-taking/venn-nvim/README.md b/lua/astrocommunity/note-taking/venn-nvim/README.md index 6742cd5b1..19bf06d0f 100644 --- a/lua/astrocommunity/note-taking/venn-nvim/README.md +++ b/lua/astrocommunity/note-taking/venn-nvim/README.md @@ -2,6 +2,8 @@ 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 @@ -21,5 +23,3 @@ Draw ASCII diagrams in Neovim with ease. │ E │◄─────────┘ └───┘ ``` - -**Repository:**