Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

# diffmt.nvim

Neovim plugin that opens formatted content by formatter in diff window

image

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