Giter VIP home page Giter VIP logo

comment-box.nvim's Introduction

comment-box.nvim

comment-box

You have this long config file and you want to clearly (and beautifully) separate each part. So you put lines of symbols as separators. Boxes would have been better but too tedious to make, not to mention if you want to center your text in it.

This plugin tries to remedy this by giving you easy boxes and lines the way you want them to be.

Prerequisite

Neovim 0.5+

Installation

Install like any other plugin with your favorite package manager.

For example with packer:

use("LudoPinelli/comment-box.nvim")

Note: comment-box does not come with any keybinding (see below to make your own)

Usage

To put some text in a box

Put your cursor on the line you want in a box, or select multiple lines, then use one of the two functions provided:

-- To draw a box with the text left-aligned:
:lua require("comment-box").lbox()

-- To draw a box with the text centered:
:lua require("comment-box").cbox()

To draw a line

In normal or insert mode, use:

:lua require("comment-box").line()

Keybindings examples

Vim script:

nnoremap <Leader>bb <Cmd>lua require('comment-box').lbox()<CR>
vnoremap <Leader>bb <Cmd>lua require('comment-box').lbox()<CR>

nnoremap <Leader>bc <Cmd>lua require('comment-box').cbox()<CR>
vnoremap <Leader>bc <Cmd>lua require('comment-box').cbox()<CR>

nnoremp <Leader>bl <Cmd>lua require('comment-box').line()<CR>
inoremp <M-l> <Cmd>lua require('comment-box').line()<CR>

Lua

local keymap = vim.api.nvim_set_keymap

keymap("n", "<Leader>bb", "<Cmd>lua require('comment-box').lbox()<CR>", {})
keymap("v", "<Leader>bb", "<Cmd>lua require('comment-box').lbox()<CR>", {})

keymap("n", "<Leader>bc", "<Cmd>lua require('comment-box').cbox()<CR>", {})
keymap("v", "<Leader>bc", "<Cmd>lua require('comment-box').cbox()<CR>", {})

keymap("n", "<Leader>bl", "<Cmd>lua require('comment-box').line()<CR>", {})
keymap("i", "<M-l>", "<Cmd>lua require('comment-box').line()<CR>", {})

Or if you use Neovim-nightly:

local keymap = vim.keymap.set

keymap({ "n", "v"}, "<Leader>bb", require('comment-box').lbox, {})
keymap({ "n", "v"}, "<Leader>bc", require('comment-box').cbox, {})

keymap("n", "<Leader>bl", require('comment-box').line, {})
keymap("i", "<M-l>", require('comment-box').line, {})

Configuration

You can call the setup function in your init.lua(.vim) to configure the way comment-box does its things. Here is the list of the options with their default value:

require('comment-box').setup({
	width = 70, -- width of the box/line
	borders = { -- symbols used to draw a box
		horizontal = "",
		vertical = "",
		top_left = "",
		top_right = "",
		bottom_left = "",
		bottom_right = "",
	},
  line_symbol = "", -- symbol used to draw a line
  outer_blank_lines = false, -- insert a blank line above and below the box
  inner_blank_lines = false, -- insert a blank line above and below the text
})

width

Width of the boxes and lines

border

To change the look of your boxes:

ASCII box

line_symbol

To change the look of your lines

outer_blank_line and inner_blank_lines

blank lines

Known issues

comment-box doesn't (yet) wrap texts longer than the width of the box.

Acknowledgement

I learned and borrow from those plugins' code:

comment-box.nvim's People

Contributors

ludopinelli avatar

Watchers

 avatar

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.