Skip to content

ZNielsen/nvim-blockformatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • 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>

About

A small block formatting plugin for Neovim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published