From f0b0787c91a178ad0a1ee4a1befdbf492c041c02 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Wed, 4 Jun 2025 13:55:59 -0400 Subject: [PATCH 1/2] qol changes to formatters/keymaps --- nix/neovim-overlay.nix | 6 +++++- nvim/ftplugin/nix.lua | 6 +++--- nvim/init.lua | 2 +- nvim/plugin/autocommands.lua | 3 --- nvim/plugin/conform.lua | 16 +++++++++++----- nvim/plugin/telescope.lua | 11 +++-------- nvim/plugin/which-key.lua | 1 + 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 1be8739..35cd41f 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -103,7 +103,7 @@ with final.pkgs.lib; let lua-language-server clang-tools # provides clangd which is a c/c++ lsp jdt-language-server # java ls - nixd # nix LSP + nil # nix lsp rust-analyzer # rust LSP vscode-langservers-extracted # various web dev lsps from vscode typescript-language-server # css lsp thing @@ -116,6 +116,10 @@ with final.pkgs.lib; let rustfmt # rust formatter prettierd # typescript/javascript formatter # google-java-format # java formatter based off google guidelines + + # extra required packages + gcc + nodejs ]; in { # This is the neovim derivation diff --git a/nvim/ftplugin/nix.lua b/nvim/ftplugin/nix.lua index 7fee20e..0d4aac8 100644 --- a/nvim/ftplugin/nix.lua +++ b/nvim/ftplugin/nix.lua @@ -1,5 +1,5 @@ -- Exit if the language server isn't available -if vim.fn.executable('nixd') ~= 1 then +if vim.fn.executable('nil') ~= 1 then return end @@ -11,8 +11,8 @@ local root_files = { local lsp = require('user.lsp') vim.lsp.start { - name = 'nixd', - cmd = { 'nixd' }, + name = 'nil', + cmd = { 'nil' }, root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]), capabilities = lsp.make_client_capabilities(), on_attach = lsp.on_attach, diff --git a/nvim/init.lua b/nvim/init.lua index 79b8c5a..32d3e73 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -22,7 +22,7 @@ end opt.path = vim.o.path .. '**' opt.number = true -opt.relativenumber = false +opt.relativenumber = true opt.cursorline = true opt.lazyredraw = true opt.showmatch = true -- Highlight matching parentheses, etc diff --git a/nvim/plugin/autocommands.lua b/nvim/plugin/autocommands.lua index cd8ceb6..86c5238 100644 --- a/nvim/plugin/autocommands.lua +++ b/nvim/plugin/autocommands.lua @@ -89,9 +89,6 @@ vim.api.nvim_create_autocmd('LspAttach', { keymap.set('n', '', vim.lsp.codelens.run, desc('[lsp] run code lens')) keymap.set('n', 'cr', vim.lsp.codelens.refresh, desc('lsp [c]ode lenses [r]efresh')) keymap.set('n', 'gr', vim.lsp.buf.references, desc('lsp [g]et [r]eferences')) - keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, desc('[lsp] [f]ormat buffer')) if client and client.server_capabilities.inlayHintProvider then keymap.set('n', 'h', function() local current_setting = vim.lsp.inlay_hint.is_enabled { bufnr = bufnr } diff --git a/nvim/plugin/conform.lua b/nvim/plugin/conform.lua index af3e755..7b556ad 100644 --- a/nvim/plugin/conform.lua +++ b/nvim/plugin/conform.lua @@ -4,6 +4,7 @@ require('conform').setup { nix = { 'alejandra' }, rust = { 'rustfmt' }, typescript = { 'prettierd' }, + -- Conform will run multiple formatters sequentially -- python = { "isort", "black" }, -- You can customize some of the format options for the filetype (:help conform.format) @@ -11,9 +12,14 @@ require('conform').setup { -- Conform will run the first available formatter -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, - format_on_save = { - -- These options will be passed to conform.format() - timeout_ms = 500, - lsp_format = 'fallback', - }, + format_on_save = nil, + -- format_on_save = { + -- -- These options will be passed to conform.format() + -- timeout_ms = 500, + -- lsp_format = 'fallback', + -- }, } + +vim.keymap.set('n', 'f', function() + require('conform').format { async = true } +end, { desc = '[f]ormat buffer' }) diff --git a/nvim/plugin/telescope.lua b/nvim/plugin/telescope.lua index 490dd75..6e248b4 100644 --- a/nvim/plugin/telescope.lua +++ b/nvim/plugin/telescope.lua @@ -27,14 +27,9 @@ vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) -vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) +vim.keymap.set('n', 'se', builtin.diagnostics, { desc = '[S]earch [E]rrors' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) -vim.keymap.set( - 'n', - 'fb', - ':Telescope file_browser', - { desc = '[F]ile [B]rowser', noremap = true, silent = true } -) +vim.keymap.set('n', 'sd', ':Telescope file_browser', { desc = 'Search [D]irectory' }) telescope.setup { defaults = { @@ -57,7 +52,7 @@ telescope.setup { local multi = picker:get_multi_selection() actions.select_default(pb) -- the normal enter behaviour for _, j in pairs(multi) do - if j.path ~= nil then -- is it a file -> open it as well: + if j.path ~= nil then -- is it a file -> open it as well: vim.cmd(string.format('%s %s', 'edit', j.path)) end end diff --git a/nvim/plugin/which-key.lua b/nvim/plugin/which-key.lua index 08df1f4..26b8be2 100644 --- a/nvim/plugin/which-key.lua +++ b/nvim/plugin/which-key.lua @@ -11,6 +11,7 @@ wk.add { { 's', group = '[S]earch' }, { 'w', group = '[W]orkspace' }, { 't', group = '[T]oggle' }, + { 'f', group = '[F]ormat' }, { 'g', group = '[G]it' }, { 'p', group = '[P]eek' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, From 725b32dbcdf5bb8aed61357745c31cf93cbd2401 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Wed, 4 Jun 2025 15:08:20 -0400 Subject: [PATCH 2/2] conform: set format keybind to fallback on lsp formatter --- nvim/plugin/conform.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvim/plugin/conform.lua b/nvim/plugin/conform.lua index 7b556ad..c604c44 100644 --- a/nvim/plugin/conform.lua +++ b/nvim/plugin/conform.lua @@ -21,5 +21,5 @@ require('conform').setup { } vim.keymap.set('n', 'f', function() - require('conform').format { async = true } + require('conform').format { async = true, lsp_format = 'fallback' } end, { desc = '[f]ormat buffer' })