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.
Neovim 0.5+
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)
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()
In normal or insert mode, use:
:lua require("comment-box").line()
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>
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, {})
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 of the boxes and lines
To change the look of your boxes:
To change the look of your lines
comment-box doesn't (yet) wrap texts longer than the width of the box.
I learned and borrow from those plugins' code: