jbyuki / venn.nvim

Draw ASCII diagrams in Neovim
MIT License
919 stars 20 forks source link

Add KeyMapping section to readme #8

Closed joshzcold closed 2 years ago

joshzcold commented 2 years ago

I'm curious if you would like to add a "Key Mapping" section to your readme? I found it useful to execute VBox commands via HJKL for smooth line drawing.

Preview from Readme:

Key Mapping

In a lua function:

vim.cmd[[setlocal ve=all]]
vim.api.nvim_buf_set_keymap(0, "n", "J", "<C-v>j:VBox<cr>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "K", "<C-v>k:VBox<cr>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "L", "<C-v>l:VBox<cr>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "n", "H", "<C-v>h:VBox<cr>", {noremap = true})
vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<cr>", {noremap = true})

veenDemo

jbyuki commented 2 years ago

Sorry for the late response. I was away from the screen for a couple of days.

First, this is really cool! I never thought of using it like that. As for the README, I feel like a lot of users of this plugin are Neovim beginners. It might not be immediately clear how you would use it using these instructions.

Maybe more explicit instructions would be better.

I would then add it to the README.

diego-rapoport commented 2 years ago

Sorry for the late response. I was away from the screen for a couple of days.

First, this is really cool! I never thought of using it like that. As for the README, I feel like a lot of users of this plugin are Neovim beginners. It might not be immediately clear how you would use it using these instructions.

Maybe more explicit instructions would be better.

  • Explicit the lua functions around the code.
  • How you would call them?
  • Maybe also add a stop function which includes (set ve=)

I would then add it to the README.

Yeah, I really would like to use it!! Is it possible to make it part of the setup? Not necessarily the default behaviour, but as an option could be interesting.

joshzcold commented 2 years ago

trying to do a toggle function by having a flippable variable.

                 local venn_enabled = vim.api.nvim_buf_get_var(0, "venn_enabled")
                 if(not venn_enabled) then

however in lua the first line errors out with a missing variable and the rest of the code doesn't get executed.

What I would like is for the nvim.buf_get_var to return null so I can conditionally set it. Anyone have an idea? maybe I just set the variable to true on config initalization then ill have it ready?

jbyuki commented 2 years ago

Did you already solve the issue? Ran into the same problem with another plugin. You can either wrap it in a pcall, otherwise using meta-accessors would be shorter.

joshzcold commented 2 years ago

This seems to work well

-- enable or disable keymappings for venn
function _G.toggle_venn()
    local venn_enabled = vim.inspect(vim.b.venn_enabled) 
    if(venn_enabled == "nil") then
        vim.b.venn_enabled = true
        vim.cmd[[setlocal ve=all]]
        vim.api.nvim_buf_set_keymap(0, "n", "J", "<C-v>j:VBox<cr>", {noremap = true})
        vim.api.nvim_buf_set_keymap(0, "n", "K", "<C-v>k:VBox<cr>", {noremap = true})
        vim.api.nvim_buf_set_keymap(0, "n", "L", "<C-v>l:VBox<cr>", {noremap = true})
        vim.api.nvim_buf_set_keymap(0, "n", "H", "<C-v>h:VBox<cr>", {noremap = true})
        vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<cr>", {noremap = true})
    else
        vim.cmd[[setlocal ve=]]
        vim.cmd[[mapclear <buffer>]]
        vim.b.venn_enabled = nil
    end

end
-- toggle keymappings for venn
vim.api.nvim_set_keymap('n', '<leader>dz', ":lua toggle_venn()<cr>", { noremap = true})
joshzcold commented 2 years ago

README is updated with new function.

jbyuki commented 2 years ago

That's perfect! I haven't tested on my machine but I will merge as-is. Feel free to pull other requests if you have.