-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconform.lua
More file actions
72 lines (63 loc) · 1.6 KB
/
Copy pathconform.lua
File metadata and controls
72 lines (63 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- Lightweight yet powerful formatter plugin for Neovim
local function formatBuffer(bufnr)
-- if bufnr is not provided, it will format the current buffer
local opts = {
bufnr = bufnr,
timeout_ms = 3000,
async = false,
quiet = false,
lsp_fallback = true,
}
require("conform").format(opts)
end
local function formatOnSave(bufnr)
if vim.g.disable_autoformat then
return
end
formatBuffer(bufnr)
end
return {
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
opts = {
},
init = function()
local conform_augroup = vim.api.nvim_create_augroup("conform", { clear = true })
-- Save on write
vim.api.nvim_create_autocmd("BufWritePre", {
group = conform_augroup,
callback = function(args)
formatOnSave(args.buf)
end,
})
-- Disable format on save
vim.api.nvim_create_user_command("FormatDisable", function()
vim.g.disable_autoformat = true
end, {
desc = "Disable autoformat-on-save(conform)",
bang = true,
})
-- Enable format on save
vim.api.nvim_create_user_command("FormatEnable", function()
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save(conform)",
})
-- Format
vim.api.nvim_create_user_command("Format", function()
formatBuffer()
end, {
desc = "Format (conform)",
})
-- Get format info
vim.api.nvim_create_user_command("FormatInfo", function()
require("conform.health").show_window()
end, {
desc = "Format info(conform)",
})
end,
keys = {
{ "<leader>cf", '<cmd>Format<cr>', desc = "Format code", },
{ '<leader>if', '<cmd>ConformInfo<cr>', desc = "Format(conform) info" }
},
}