Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hexium310/diffmt.nvim
Neovim plugin that opens formatted content by formatter in diff window
https://github.com/hexium310/diffmt.nvim
neovim neovim-plugin nvim nvim-plugin
Last synced: 24 days ago
JSON representation
Neovim plugin that opens formatted content by formatter in diff window
- Host: GitHub
- URL: https://github.com/hexium310/diffmt.nvim
- Owner: hexium310
- License: mit
- Created: 2022-02-20T16:39:16.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-03-12T16:05:01.000Z (over 2 years ago)
- Last Synced: 2023-02-28T00:26:22.814Z (over 1 year ago)
- Topics: neovim, neovim-plugin, nvim, nvim-plugin
- Language: Lua
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# diffmt.nvim
Neovim plugin that opens formatted content by formatter in diff window
## Motivation
Formatters for programming languages are useful;
however even if we want not to use some rules, most formatters such as `rustfmt` and `StyLua` doesn't have the ability to disable some of their rules.
In this case, we had to reluctantly use formatter with all rules or stop use of formatter.
This plugin opens the formatted content in diff window (`:h diff`) so that makes it easy to cherry-pick changes by formatting, e.g. to apply reordering imports in rust.## Installation
Use package manager you use.
For dein:```vim
call dein#add('hexium310/diffmt.nvim')
```## Usage
You can use it as it is if you don't need to customize configuration.
Open a target file to the buffer then execute following command:```lua
lua require('diffmt').diff()
```Note that it will be formatted against not an actual file but the content in the current buffer.
### Customization
This is the default configuration, a passed configuration will be extended based on default:
```lua
require('diffmt').setup({
-- Commands you dont't want to execute
disables = {},
-- Pairs of command and formatter configuration
formatters = {
rustfmt = {
-- Name or path for an executable command
command = 'rustfmt',
-- Command arguments. Specify arguments to read the content from standart input and emit all content in the file to the standard output after formatted
args = {
'--emit',
'stdout',
},
-- Filetypes in which the command will be executed
filetypes = {
'rust',
},
},
stylua = {
command = 'stylua',
args = {
'-',
},
filetypes = {
'lua',
},
},
},
})
```You can use add unsupported formatters:
```lua
{
formatters = {
prettier = {
command = 'npx',
args = {
'prettier',
'--parser',
'babel',
},
filetypes = {
'javascript',
'javascriptreact',
},
},
},
}
```Also you can create a pull request or an issue to add support.
## Supported formatters
- [rustfmt]
- [StyLua][rustfmt]: https://github.com/rust-lang/rustfmt
[StyLua]: https://github.com/JohnnyMorganz/StyLua