From 7325c06a759e9a6d7bb7a41e733c06c242b06dcb Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:41:08 -0500 Subject: [PATCH] change format keymap to use conform to format --- nvim/lua/juancwu/plugins/lsp/init.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nvim/lua/juancwu/plugins/lsp/init.lua b/nvim/lua/juancwu/plugins/lsp/init.lua index 9d46a22..172b398 100644 --- a/nvim/lua/juancwu/plugins/lsp/init.lua +++ b/nvim/lua/juancwu/plugins/lsp/init.lua @@ -52,7 +52,7 @@ return { lspzero.preset({}) - lspzero.on_attach(function(client, bufnr) + lspzero.on_attach(function(_, bufnr) lspzero.default_keymaps({ buffer = bufnr, omit = { @@ -60,26 +60,30 @@ return { }, }) - function nmap(key, action, desc) + local function nmap(key, action, desc) vim.keymap.set("n", key, action, { desc = "LSP: " .. desc, }) end + local function format() + require("conform").format({ bufnr = bufnr }) + end + nmap("[d", "lua vim.diagnostic.goto_prev()", "Goto Prev Diagnostic") nmap("]d", "lua vim.diagnostic.goto_next()", "Goto Next Diagnostic") - local current_dir = vim.fn.expand("%:p:h") + -- local current_dir = vim.fn.expand("%:p:h") -- vim.keymap.set('n', 'gr', 'Telescope lsp_references', { buffer = true }) -- format with space + f -- vim.keymap.set("n", "fb", "lua vim.lsp.buf.format()", -- { desc = "[F]ormat [B]uffer" }) - nmap("fb", "lua vim.lsp.buf.format()", "[F]ormat [B]uffer") + nmap("fb", format, "[F]ormat [B]uffer") vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) - require("conform").format({ bufnr = bufnr }) + format() end, { desc = "Format current buffer with LSP" }) end)