aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md37
1 files changed, 34 insertions, 3 deletions
diff --git a/README.md b/README.md
index 88730a1..0999d60 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# conform.nvim
-Formatter plugin for Neovim
+Lightweight yet powerful formatter plugin for Neovim
<!-- TOC -->
@@ -9,6 +9,7 @@ Formatter plugin for Neovim
- [Setup](#setup)
- [Formatters](#formatters)
- [Options](#options)
+- [Autoformat on save](#autoformat-on-save)
- [API](#api)
- [format(opts)](#formatopts)
- [list_formatters(bufnr)](#list_formattersbufnr)
@@ -114,8 +115,6 @@ require("conform").setup({
formatters = { "isort", "black" },
-- Run formatters one after another instead of stopping at the first success
run_all_formatters = true,
- -- Don't run these formatters as part of the format_on_save autocmd (see below)
- format_on_save = false
},
},
})
@@ -266,6 +265,38 @@ require("conform").formatters.my_formatter = {
<!-- /OPTIONS -->
+## Autoformat on save
+
+If you want more complex logic than the `format_on_save` option allows, you can write it yourself
+using your own autocmd. For example:
+
+<!-- AUTOFORMAT -->
+
+```lua
+vim.api.nvim_create_autocmd("BufWritePre", {
+ pattern = "*",
+ callback = function(args)
+ -- Disable autoformat on certain filetypes
+ local ignore_filetypes = { "sql", "java" }
+ if vim.tbl_contains(ignore_filetypes, vim.bo[args.buf].filetype) then
+ return
+ end
+ -- Disable with a global or buffer-local variable
+ if vim.g.disable_autoformat or vim.b[args.buf].disable_autoformat then
+ return
+ end
+ -- Disable autoformat for files in a certain path
+ local bufname = vim.api.nvim_buf_get_name(args.buf)
+ if bufname:match("/node_modules/") then
+ return
+ end
+ require("conform").format({ timeout_ms = 500, lsp_fallback = true, buf = args.buf })
+ end,
+})
+```
+
+<!-- /AUTOFORMAT -->
+
## API
<!-- API -->