All Projects → LudoPinelli → comment-box.nvim

LudoPinelli / comment-box.nvim

Licence: MIT license
✨ Clarify and beautify your comments using boxes and lines.

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to comment-box.nvim

Comment.nvim
🧠 💪 // Smart and powerful comment plugin for neovim. Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more
Stars: ✭ 796 (+774.73%)
Mutual labels:  nvim, comment, neovim-plugin, commenting
neogen
A better annotation generator. Supports multiple languages and annotation conventions.
Stars: ✭ 339 (+272.53%)
Mutual labels:  nvim, comment, neovim-plugin
nvim-config
My neovim config
Stars: ✭ 63 (-30.77%)
Mutual labels:  nvim, neovim-plugin
modes.nvim
Prismatic line decorations for the adventurous vim user
Stars: ✭ 299 (+228.57%)
Mutual labels:  nvim, neovim-plugin
neovim-lua-plugin-boilerplate
Starter template for creating Neovim Lua plugins
Stars: ✭ 28 (-69.23%)
Mutual labels:  nvim, neovim-plugin
Lsp Status.nvim
Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
Stars: ✭ 201 (+120.88%)
Mutual labels:  nvim, neovim-plugin
Coc.nvim
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Stars: ✭ 18,268 (+19974.73%)
Mutual labels:  nvim, neovim-plugin
code runner.nvim
Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
Stars: ✭ 234 (+157.14%)
Mutual labels:  nvim, neovim-plugin
Nvim Hlslens
Hlsearch Lens for Neovim
Stars: ✭ 55 (-39.56%)
Mutual labels:  nvim, neovim-plugin
tabby.nvim
A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
Stars: ✭ 232 (+154.95%)
Mutual labels:  nvim, neovim-plugin
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (+15.38%)
Mutual labels:  nvim, neovim-plugin
firvish.nvim
WIP
Stars: ✭ 31 (-65.93%)
Mutual labels:  nvim, neovim-plugin
Lualine.nvim
A blazing fast and easy to configure neovim statusline written in pure lua.
Stars: ✭ 198 (+117.58%)
Mutual labels:  nvim, neovim-plugin
Acid.nvim
Asynchronous Clojure Interactive Development
Stars: ✭ 147 (+61.54%)
Mutual labels:  nvim, neovim-plugin
qf helper.nvim
A collection of improvements for the quickfix buffer
Stars: ✭ 70 (-23.08%)
Mutual labels:  nvim, neovim-plugin
Nvim Bqf
Better quickfix window in Neovim, polish old quickfix window.
Stars: ✭ 120 (+31.87%)
Mutual labels:  nvim, neovim-plugin
nvim-todoist.lua
Todoist plugin for Neovim in pure Lua, inspired by https://github.com/romgrk/todoist.nvim, which you should use instead
Stars: ✭ 22 (-75.82%)
Mutual labels:  nvim, neovim-plugin
nvim-highlite
A colorscheme template that is "lite" on logic for the developer.
Stars: ✭ 163 (+79.12%)
Mutual labels:  nvim, neovim-plugin
Chadtree
File manager for Neovim. Better than NERDTree.
Stars: ✭ 653 (+617.58%)
Mutual labels:  nvim, neovim-plugin
Semshi
🌈 Semantic Highlighting for Python in Neovim
Stars: ✭ 758 (+732.97%)
Mutual labels:  nvim, neovim-plugin

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.

Overview

comment-box allows you to:

  • draw a box around the selected text or actual line with a simple keyboard shortcut. The box can be left aligned or centered, can have a fixed size or be adapted to the text. The text can be left aligned or centered. Too long text are automatically wrapped to fit in the box.
  • create your own type of box by choosing its width and the characters used to draw the top, bottom, left, right and corners of it.
  • draw a line with a simple keyboard shortcut. The line can be left aligned or centered.
  • create your own type of line by choosing its width and the characters used to draw its start, end and body.
  • choose from a catalog of 22 predefined boxes and 10 predefined lines and use it by simply pass its number to the function call.

Mainly designed for code comments, comment-box can also be used to brighten up the dull .txt files! You can also use it in markdown and orgmode files, however, if it makes sense if you use those formats "as is" (for note taking for example), it's not a good idea if you plan to convert them to other formats.

Prerequisite

Neovim 0.5+

Installation

Install like any other plugin with your favorite package manager.

For example with packer:

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

If you're fine with the default settings (see Configuration), it's all you have to do, however, comment-box does not come with any keybinding, see Keybindings examples to make your own.

Usage

Commands

Boxes

Command Description function
CBlbox[num] Left aligned box of fixed size with Left aligned text require("comment-box").lbox([num])
CBclbox[num] Centered box of fixed size with Left aligned text require("comment-box").clbox([num])
CBcbox[num] Left aligned box of fixed size with centered text require("comment-box").cbox([num])
CBccbox[num] Centered box of fixed size with centered text require("comment-box").ccbox([num])
CBalbox[num] Left aligned adapted box with Left aligned text require("comment-box").albox([num])
CBaclbox[num] Centered adapted box with Left aligned text require("comment-box").aclbox([num])
CBacbox[num] Left aligned adapted box with centered text require("comment-box").acbox([num])
CBaccbox[num] Centered adapted box with centered text require("comment-box").accbox([num])

The [num] parameter is optional. It's the number of a predefined style from the catalog (see Catalog). By leaving it empty, the box or line will be drawn with the style you defined or if you didn't define one, with the default style.

A 'centered' box is centered relatively to the width of your document (set to the standard 80 by default, you can change it with the setup() function - see Configuration)

An 'adapted' box means than the box width will be adapted to the width of the text. However, if the width of the text exceed the width of the document, the box will have the width of the document.

To draw a box, place your cursor on the line of text you want in a box, or select multiple lines in visual mode, then use one of the command/function above.

Note: if a line is too long to fit in the box, comment-box will automatically wrap it for you.

Examples:

-- A left aligned fixed size box with the text left justified:
:CBlbox
-- or
:lua require("comment-box").lbox()

-- A centered fixed size box with the text centered:
:CBccbox
-- or
:lua require("comment-box").ccbox()

-- A centered adapted box with the text centered:
:CBaccbox
-- or
:lua require("comment-box").accbox()

-- A left aligned fixed size box with the text left justified,
-- using the syle 17 from the catalog:
:CBlbox17
-- or
:lua require("comment-box").lbox(17)

Lines

Command Description function
CBline[num] Left aligned line require("comment-box").line([num])
CBcline[num] Centered line require("comment-box").cline([num])

To draw a line, place your cursor where you want it and in normal or insert mode, use one of the command/function above.

Note: a line is centered relatively to the width of your document (set to the standard 80 by default, you can change it with the setup() function - see Configuration)

Examples:

-- A left aligned line:
:CBline
-- or
:lua require("comment-box").line()

-- A centered line:
:CBcline
-- or
:lua require("comment-box").cline()

-- A centered line using the style 6 from the catalog:
:CBcline6
-- or
:lua require("comment-box").cline(4)

Keybindings examples

Vim script:

# left aligned fixed size box with left aligned text
nnoremap <Leader>bb <Cmd>lua require('comment-box').lbox()<CR>
vnoremap <Leader>bb <Cmd>lua require('comment-box').lbox()<CR>

# centered adapted box with centered text
nnoremap <Leader>bc <Cmd>lua require('comment-box').accbox()<CR>
vnoremap <Leader>bc <Cmd>lua require('comment-box').accbox()<CR>

# centered line
nnoremap <Leader>bl <Cmd>lua require('comment-box').cline()<CR>
inoremap <M-l> <Cmd>lua require('comment-box').cline()<CR>

Lua

local keymap = vim.api.nvim_set_keymap

-- left aligned fixed size box with left aligned text
keymap("n", "<Leader>bb", "<Cmd>lua require('comment-box').lbox()<CR>", {})
keymap("v", "<Leader>bb", "<Cmd>lua require('comment-box').lbox()<CR>", {})

-- centered adapted box with centered text
keymap("n", "<Leader>bc", "<Cmd>lua require('comment-box').accbox()<CR>", {})
keymap("v", "<Leader>bc", "<Cmd>lua require('comment-box').accbox()<CR>", {})

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

Or if you use Neovim-nightly:

local keymap = vim.keymap.set
local cb = require("comment-box")

-- left aligned fixed size box with left aligned text
keymap({ "n", "v"}, "<Leader>bb", cb.lbox, {})
-- centered adapted box with centered text
keymap({ "n", "v"}, "<Leader>bc", cb.accbox, {})

-- centered line
keymap("n", "<Leader>bl", cb.cline, {})
keymap("i", "<M-l>", cb.cline, {})

The catalog

The catalog

The catalog is a collection of 22 predefined types of boxes and 10 types of lines. You can easily access the catalog in Neovim (it will appear in a popup window so it won't mess with what you're doing) using:

:CBcatalog
-- or
:lua require("comment-box").catalog()

Just take note of the number of the type of box or line you want to use, close the catalog and pass the number to the function. For example:

-- A box with the text centered and the predefined type of box n°10:
:CBcbox10
-- or
:lua require("comment-box").cbox(10)

-- A line with the predefined type of line n°4:
:CBline4
-- or
:lua require("comment-box").line(4)

Or if you found one (or more) you will frequently use, you may want to include it in you keybindings.

Note: in addition to the usual way of closing windows, you can simply use q to close the catalog.

The type n°1 for the box and line is the default one, so, if you didn't change the default settings via the setup() function (see Configuration), passing nothing or 1 (or even 0) will lead to the same result.

Configuration and creating your own type of box

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

require('comment-box').setup({
	doc_width = 80, -- width of the document
	box_width = 60, -- width of the boxes
	borders = { -- symbols used to draw a box
		top = "",
		bottom = "",
		left = "",
		right = "",
		top_left = "",
		top_right = "",
		bottom_left = "",
		bottom_right = "",
	},
  line_width = 70, -- width of the lines
  line = { -- symbols used to draw a line
		line = "",
		line_start = "",
		line_end = "",
    }
  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
  line_blank_line_above = false, -- insert a blank line above the line
  line_blank_line_below = false, -- insert a blank line below the line
})

doc_width

Width of the document. It is used to center the boxes and lines and determine the max width of the adapted boxes.

box_width

Width of the fixed size boxes (must be <= doc_width).

borders

The symbols used to draw the boxes. Let your creativity go wild! Or just use the default or choose from the predefined ones (see Catalog).

If you want an element of the box to be invisible, you can use either " "(space) or ""(empty string).

You can even create very ugly ones, no judgement!

ASCII box

line_width

Width of the lines.

line

The symbols used to draw the lines. Let your creativity go wild! Or just use the default or choose from the predefined ones (see Catalog).

outer_blank_lines and inner_blank_lines

blank lines

line_blank_line_above and line_blank_line_below

Self explanatory!

Acknowledgement

I learned and borrow from those plugins' code:

@HiPhish for his excellent advice to make the code a bit better (I'm still working on it...).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].