Coder Social home page Coder Social logo

venn.nvim's Introduction

venn.nvim

Draw ASCII diagrams in Neovim.

Installation

Install using your prefered method:

Plug 'jbyuki/venn.nvim'
use "jbyuki/venn.nvim"

Usage

  • set virtualedit=all or set ve=all. This will allow you to freely move the cursor in the buffer. (see help virtualedit).

  • Enter in Visual Block mode using <C-v> or <C-q>. Select the region where the box should be.

  • Invoke :VBox. This will draw a rectangle. In case, it has a width or a height of 1, it will draw a line.

Key Mapping

Any modal keymapping system would work to get additional keys usable for drawing and moving selections, since there are many options to draw and move around pieces.

Draw diagrams

A relative complete configuration to draw diagrams with boxes, lines and arrows in utf can be found in the hydra wiki and the more extensive version including explanations in this repo wiki.

Moving selection

Drawing and text repositioning is a frequent operation on more complex graphics. While gR allows to overwrite text from left to right, it does not allow to move (text) selections around. Using mini.move works with for now main usability restriction of no correct fixup after collisions and an example configuration can be found in the hydra wiki and the more extensive version including explanations in this repo wiki.

Using toggle command

You can map :VBox commands to allow different ways of drawing lines.

Use the following function in your neovim config to toggle drawing lines on HJKL directional keys to allow for faster creation of diagrams:

-- venn.nvim: enable or disable keymappings
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]]
        -- draw a line on HJKL keystokes
        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})
        -- draw a box by pressing "f" with visual selection
        vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<CR>", {noremap = true})
    else
        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
-- toggle keymappings for venn using <leader>v
vim.api.nvim_set_keymap('n', '<leader>v', ":lua Toggle_venn()<CR>", { noremap = true})

veenDemo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.