A simple and lightweight Neovim plugin for formatting your code.
This project is inspired by vim-rt-format.
- Automatically format on (pressing) enter (the newline).
- Supports different languages and formatters.
- Configurable and easy to set up.
- Written in Lua.
- Support both locally installed and Mason installed formatters
- Nvim with "python3" feature
- Python module "autopep8"
clang-format
executable for C family formattingstylua
executable for Lua formatting
You can install reform.nvim
using your favorite plugin manager.
local Plug = vim.fn['plug#']
vim.call('plug#begin')
Plug('gowaylee/reform.nvim')
vim.call('plug#end')
{
"gowaylee/reform.nvim",
config = function()
require("reform").setup({
-- Your configuration goes here
})
end,
}
The plugin can be configured by passing a table to the setup
function. Here are the available configuration options:
- on_insert_leave (boolean, default:
true
): Enable formatting when leaving insert mode. - auto_enable (table): Configuration for auto-enabling formatting on specific file types.
- enabled (boolean, default:
false
): Master switch for auto-enabling formatting. - filetypes (table): List of file types to auto-enable formatting for.
- exclude_filetypes (table): List of file types to exclude from auto-enable.
- enabled (boolean, default:
- formatters (table): Mapping of formatters respect to their executable path.
- mason (boolean, default:
true
): Enable Mason.nvim intergration. - debug (boolean, default:
false
): Enable debug information for troubleshooting.
require("reform").setup({
on_insert_leave = true, -- Enable formatting when leaving insert mode
auto_enable = {
enabled = false, -- Master switch for auto-enable
filetypes = { -- Filetypes to auto-enable
"python",
"lua",
"java",
"javascript",
"json",
"actionscript",
"ruby",
"c",
"cpp",
},
exclude_filetypes = {}, -- Filetypes to exclude from auto-enable
},
-- Executable paths for formatters (empty = Mason if mason or PATH, DISABLE = disabled)
formatters = {
stylua = "", -- Lua formatter
clang_format = "", -- C/C++ formatter
},
mason = true, -- Enable Mason.nvim integration
debug = false, -- Enable debug info
)
Currently, reform supports stylua
and clang-format
for language specific formatting. For other languages, such as Python, Java, JavaScript, reform will use autopep8
module in Python3
to perform formatting as a fallback.
You do not need to explicitly configure autopep8
, since it has already been fully implemented by reform. The only thing you needs to do is to ensure your NVim has installed Python3 and Pip has installed autopep8 module.
reform.nvim
currently supports the following formatters:
autopep8
from Python3, for Python, Java, JavaScript, JSON, ActionScript, Ruby.clang-format
for C family (C, C++).stylua
for Lua files.
Stylua and clang-format automatically detect configuration files in your project:
stylua.toml
.clang-format
Configuration files are searched for in:
- Current working directory (buffer file directory)
- Parent directories up to the project root
- User home directory as fallback
This project is still under development, please use with caution Report any bugs or ideas you found in Issue :)