An open API service indexing awesome lists of open source software.

https://github.com/znielsen/nvim-blockformatter

A small block formatting plugin for Neovim
https://github.com/znielsen/nvim-blockformatter

hacktober2022 hacktoberfest lua neovim

Last synced: 9 months ago
JSON representation

A small block formatting plugin for Neovim

Awesome Lists containing this project

README

          

# nvim-blockformatter
A small block formatting plugin for Neovim

| Command | Description |
|--------------------------------------|-----------------------------------------------------------------------------|
| `BlockFormatterNormalize ` | Formats a block of text to wrap at the specified column. |
| `BlockFormatterNormalizeRange ` | 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](https://github.com/wfxr/minimap.vim).

## Examples
### Block Normalization
![Block Normalization Example](https://raw.githubusercontent.com/znielsen/nvim-blockformatter/main/.github/images/block_normalizer_example.gif)

#### Example Maps
```
nnoremap bn100 :silent lua require("blockformatter.block_normalize").normalize_block_normal(vim.v.count1, 100)
nnoremap bn80 :silent lua require("blockformatter.block_normalize").normalize_block_normal(vim.v.count1, 80)
vnoremap bn100 :silent lua require("blockformatter.block_normalize").normalize_block_visual(100)
vnoremap bn80 :silent lua require("blockformatter.block_normalize").normalize_block_visual(80)
```

### Block Commenting
![Block Commenting Example](https://raw.githubusercontent.com/znielsen/nvim-blockformatter/main/.github/images/block_commenter_example.gif)

#### 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 `// `. Set to `1` would yield `/* */`.

#### Example Maps
```
nnoremap \\ :silent lua require('blockformatter.block_comment').toggle_comment_normal(vim.v.count1)
vnoremap \\ :silent lua require('blockformatter.block_comment').toggle_comment_visual()
```
#### 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](https://raw.githubusercontent.com/znielsen/nvim-blockformatter/main/.github/images/block_aligner_example.gif)

#### Example Maps
```
nnoremap ba :silent lua require("blockformatter.block_align").token_align_auto()
vnoremap ba :silent lua require("blockformatter.block_align").token_align_visual()
```