aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Arcangeli <stevearc@stevearc.com>2023-10-02 09:35:28 -0700
committerSteven Arcangeli <stevearc@stevearc.com>2023-10-02 09:35:28 -0700
commit5563df7966e244cdd0d8ec50a81cfeb2d8358d9f (patch)
tree18f247a8d5c1fa94ffb8a587e717c1cb55fd899a
parentaf3d59da20d2bc37933df409f8fc9e24ec15e066 (diff)
doc: add a recipe for complete lazy.nvim configuration
-rw-r--r--README.md1
-rw-r--r--doc/recipes.md44
2 files changed, 45 insertions, 0 deletions
diff --git a/README.md b/README.md
index 3289b2a..5ae16e4 100644
--- a/README.md
+++ b/README.md
@@ -340,6 +340,7 @@ require("conform").formatters.my_formatter = {
- [Command to toggle format-on-save](doc/recipes.md#command-to-toggle-format-on-save)
- [Automatically run slow formatters async](doc/recipes.md#automatically-run-slow-formatters-async)
- [Add extra arguments to a formatter command](doc/recipes.md#add-extra-arguments-to-a-formatter-command)
+- [Lazy loading with lazy.nvim](doc/recipes.md#lazy-loading-with-lazynvim)
<!-- /RECIPES -->
diff --git a/doc/recipes.md b/doc/recipes.md
index 40d2c0f..2d33ca2 100644
--- a/doc/recipes.md
+++ b/doc/recipes.md
@@ -8,6 +8,7 @@
- [Command to toggle format-on-save](#command-to-toggle-format-on-save)
- [Automatically run slow formatters async](#automatically-run-slow-formatters-async)
- [Add extra arguments to a formatter command](#add-extra-arguments-to-a-formatter-command)
+- [Lazy loading with lazy.nvim](#lazy-loading-with-lazynvim)
<!-- /TOC -->
@@ -196,3 +197,46 @@ require("conform").formatters.deno_fmt = vim.tbl_deep_extend("force", deno_fmt,
-- There is also a utility to modify a formatter in-place
util.add_formatter_args(require("conform.formatters.prettier"), { "--tab", "--indent", "2" })
```
+
+## Lazy loading with lazy.nvim
+
+Here is the recommended config for lazy-loading using lazy.nvim
+
+```lua
+return {
+ "stevearc/conform.nvim",
+ event = { "BufWritePre" },
+ cmd = { "ConformInfo" },
+ keys = {
+ {
+ -- Customize or remove this keymap to your liking
+ "<leader>f",
+ function()
+ require("conform").format({ async = true, lsp_fallback = true })
+ end,
+ mode = "",
+ desc = "Format buffer",
+ },
+ },
+ -- Everything in opts will be passed to setup()
+ opts = {
+ formatters_by_ft = {
+ lua = { "stylua" },
+ python = { "isort", "black" },
+ javascript = { { "prettierd", "prettier" } },
+ },
+ format_on_save = { timeout_ms = 500, lsp_fallback = true },
+ },
+ init = function()
+ -- If you want the formatexpr, here is the place to set it
+ vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
+ end,
+
+ -- This function is optional, but if you want to customize formatters do it here
+ config = function(_, opts)
+ local util = require("conform.util")
+ util.add_formatter_args(require("conform.formatters.shfmt"), { "-i", "2" })
+ require("conform").setup(opts)
+ end,
+}
+```