Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emileferreira/nvim-strict
Strict, native code style formatting plugin for Neovim. Expose deep nesting, overlong lines, trailing whitespace, trailing empty lines, todos and inconsistent indentation.
https://github.com/emileferreira/nvim-strict
formatting lua neovim neovim-plugin nvim nvim-plugin regex
Last synced: 3 months ago
JSON representation
Strict, native code style formatting plugin for Neovim. Expose deep nesting, overlong lines, trailing whitespace, trailing empty lines, todos and inconsistent indentation.
- Host: GitHub
- URL: https://github.com/emileferreira/nvim-strict
- Owner: emileferreira
- License: mit
- Created: 2022-12-12T14:03:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-16T10:19:10.000Z (almost 2 years ago)
- Last Synced: 2024-07-31T20:51:44.496Z (5 months ago)
- Topics: formatting, lua, neovim, neovim-plugin, nvim, nvim-plugin, regex
- Language: Lua
- Homepage:
- Size: 247 KB
- Stars: 33
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - emileferreira/nvim-strict - Strict, native code style formatting which exposes deep nesting, overlong lines, trailing whitespace, trailing empty lines, todos and inconsistent indentation. (Formatting / Comment)
README
# nvim-strict
Strict, native code style formatting plugin for Neovim. Expose deep nesting, overlong lines, trailing whitespace, trailing empty lines, todos and inconsistent indentation.
![nvim-strict demo](demo.png)
Strict (or nvim-strict) is an all-Lua wrapper for a collection of regular expressions which combine to provide lightweight, IDE-like code style hints and formatting.
Strict is language agnostic; it highlights and formats properties common to all programming languages. It pairs well with the Neovim LSP client for language-specific code formatting with strict and configurable code style formatting.
## Features
* Highlights deeply-nested code
* Highlights and splits overlong lines
* Highlights and removes trailing empty lines and whitespace
* Highlights and converts tab or space indentation
* Highlights TODO comments
* Formatting functions preserve window, cursor, jumplist and search state
* Include and exclude filetypes and buftypes
* No external dependencies
* Highly configurable and extensible
* Blazingly fast## Installation
Strict can be installed using any package manager. Here is an example using [packer.nvim](https://github.com/wbthomason/packer.nvim) to install and setup Strict using the default configuration. Note that Strict is only enabled once the `setup` function has been called.
```lua
use({
'emileferreira/nvim-strict',
config = function()
require('strict').setup()
end
})
```## Configuration
Strict comes with batteries included and (IMHO) sane defaults. The default configuration is shown below. It can be modified and passed to the `setup` function to override the default values. The configuration options are documented in [strict.txt](doc/strict.txt).
```lua
local default_config = {
included_filetypes = nil,
excluded_filetypes = nil,
excluded_buftypes = { 'help', 'nofile', 'terminal', 'prompt' },
match_priority = -1,
deep_nesting = {
highlight = true,
highlight_group = 'DiffDelete',
depth_limit = 3,
ignored_trailing_characters = nil,
ignored_leading_characters = nil
},
overlong_lines = {
highlight = true,
highlight_group = 'DiffDelete',
length_limit = 80,
split_on_save = true
},
trailing_whitespace = {
highlight = true,
highlight_group = 'SpellBad',
remove_on_save = true
},
trailing_empty_lines = {
highlight = true,
highlight_group = 'SpellBad',
remove_on_save = true
},
space_indentation = {
highlight = false,
highlight_group = 'SpellBad',
convert_on_save = false
},
tab_indentation = {
highlight = true,
highlight_group = 'SpellBad',
convert_on_save = true
},
todos = {
highlight = true,
highlight_group = 'DiffAdd'
}
}
```The following is an example of a more forgiving configuration.
```lua
require('strict').setup({
excluded_filetypes = { 'text', 'markdown', 'html' },
deep_nesting = {
depth_limit = 5,
ignored_trailing_characters = ',',
ignored_leading_characters = '.'
},
overlong_lines = {
length_limit = 120
}
})
```## Bypassing
The highlights of Strict can be temporarily disabled, per window, by the following command.
```
:call clearmatches()
```The command below writes the current buffer without triggering autocmds which bypasses the format-on-save functionality of Strict.
```
:noa w
```## Keymaps
The formatting functions are exported for use in keymaps, autocmds or other plugins. Below is a basic example of using the functions in keymaps.
```lua
local strict = require('strict')
local options = { noremap = true, silent = true }
vim.keymap.set('n', 'tw', strict.remove_trailing_whitespace, options)
vim.keymap.set('n', 'tl', strict.remove_trailing_empty_lines, options)
vim.keymap.set('n', 'st', strict.convert_spaces_to_tabs, options)
vim.keymap.set('n', 'ts', strict.convert_tabs_to_spaces, options)
vim.keymap.set('n', 'ol', strict.split_overlong_lines, options)
```## Reviews
"Looks cool!" - [TJ DeVries](https://github.com/tjdevries), Neovim core maintainer
## Contributing
Pull requests, bug reports and feature requests are welcomed.