https://github.com/futarimiti/q-format
Quick format
https://github.com/futarimiti/q-format
Last synced: 2 months ago
JSON representation
Quick format
- Host: GitHub
- URL: https://github.com/futarimiti/q-format
- Owner: Futarimiti
- Created: 2023-09-27T05:37:28.000Z (over 1 year ago)
- Default Branch: v2
- Last Pushed: 2024-06-09T02:29:45.000Z (12 months ago)
- Last Synced: 2025-03-17T07:53:17.625Z (3 months ago)
- Language: Lua
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# q-format
Better formatting
## Why not the built-in formatter?
These are the things I hate:
* It clueless accepts any result, even if it's error message
* You always lose your cursor position and your focus after formatting
* Why does formatexpr deserve greater priority than formatprg anyway?## What has improved
* Formatting will not be applied if a shell error arisen
* Views will be restored after formatting
* You can specify the preference: formatexpr, formatprg, equalprg... on a filetype basis
* You can specify what to do
* Upon successful formatting, e.g. write to file
* Upon failed formatting, e.g. show error message
* At the end of formatting, e.g. `normal! zz`
* When formatting does not apply## Installation
```lua
-- lazy.nvim
return
{ 'Futarimiti/q-format'
, branch = 'v2'
, config = function () require('q-format').setup() end
}
```## Customisation
For complete options, with their type, defaults and descriptions,
see [config/defaults.lua](lua/q-format/config/defaults.lua).Q-format provides module `q-format.user` which in turn
provides function `format` to format the current buffer,
which can be used to setup keymaps or commands.
Q-format itself does bind any keymaps or commands---I
hate plugins that reach their fingers too far.```lua
local u = require 'q-format.user'
vim.keymap.set('n', 'Q', u.format)
```You may also use autocmds to format on save,
mimicking those 'auto-format' plugins,
though I would recommend against it---you
must first see the formatting result before
you can decide whether to keep it, don't you?