A small block formatting plugin for Neovim
  • Lua 91.2%
  • Vim Script 7.8%
  • Makefile 1%
Find a file
2024-11-01 07:21:56 -07:00
.github/images Adding example gif 2021-12-20 15:12:34 -08:00
doc Add block normalization and docs 2022-04-02 10:22:42 -07:00
lua/blockformatter support comment in files that use tabs 2024-11-01 07:21:56 -07:00
plugin Add block normalization and docs 2022-04-02 10:22:42 -07:00
.gitignore Add block normalization and docs 2022-04-02 10:22:42 -07:00
include.mk Wrapping comments work. Adding back padding next 2022-04-02 10:03:57 -07:00
LICENSE Initial commit 2021-12-17 09:11:32 -08:00
Makefile Wrapping comments work. Adding back padding next 2022-04-02 10:03:57 -07:00
README.md Add groovy comment support 2024-06-12 11:23:07 -07:00

nvim-blockformatter

A small block formatting plugin for Neovim

Command Description
BlockFormatterNormalize <arg> Formats a block of text to wrap at the specified column.
BlockFormatterNormalizeRange <arg> Formats a visual range of text to wrap at the specified column.
BlockFormatterComment Toggles a leading comment for the line. May take a leading count argument.
BlockFormatterCommentRange Toggles a leading comment for a visual range.
BlockFormatterAlign Format trailing content to be in the same column. Takes leading count arg.
BlockFormatterAlignRange Format trailing content to be in the same column. Uses visual range.
BlockFormatterAlignAuto Format trailing content to be in the same column. See helpfile.

To use, just Plug 'ZNielsen/nvim-blockformatter' or similar. Mappings are recommended, as the command names are a bit verbose. Suggestions are below.

The minimap in the examples is minimap.vim.

Examples

Block Normalization

Block Normalization Example

Example Maps

nnoremap <leader>bn100 :<C-U>silent lua require("blockformatter.block_normalize").normalize_block_normal(vim.v.count1, 100)<CR>
nnoremap <leader>bn80  :<C-U>silent lua require("blockformatter.block_normalize").normalize_block_normal(vim.v.count1, 80)<CR>
vnoremap <leader>bn100 :<C-U>silent lua require("blockformatter.block_normalize").normalize_block_visual(100)<CR>
vnoremap <leader>bn80  :<C-U>silent lua require("blockformatter.block_normalize").normalize_block_visual(80)<CR>

Block Commenting

Block Commenting Example

Settings

  • g:prefer_wrapping_comments (default 0) - For filetypes that support both line comments and wrapping comments, set to true to prefer wrap-style comments
    • Example: C has // and /* */. Set to 0 (default) would yield // <line>. Set to 1 would yield /* <line> */.

Example Maps

nnoremap \\ :<C-U>silent lua require('blockformatter.block_comment').toggle_comment_normal(vim.v.count1)<CR>
vnoremap \\ :<C-U>silent lua require('blockformatter.block_comment').toggle_comment_visual()<CR>

Supported filetypes

  • Javascript
  • Dockerfile
  • sshconfig
  • Markdown
  • groovy
  • Python
  • golang
  • Rust
  • Ruby
  • Bash
  • Yaml
  • Toml
  • HTML
  • Lua
  • Cpp
  • CSS
  • Zig
  • Vim
  • sh
  • C

Block Alignment

Block Alignment Example

Example Maps

nnoremap <leader>ba :<C-U>silent lua require("blockformatter.block_align").token_align_auto()<CR>
vnoremap <leader>ba :<C-U>silent lua require("blockformatter.block_align").token_align_visual()<CR>