From dfc14619517587d415ce90dfd937cd91f4b636c9 Mon Sep 17 00:00:00 2001 From: moons-14 Date: Wed, 11 Mar 2026 16:01:17 +0900 Subject: [PATCH] nixvim: improve keymaps, completion, and formatter config - Add LSP code actions, diagnostic navigation, window navigation keymaps - Move telescope keymaps to explicit mkRaw form for reliability - Change buffer nav from bh/bl to [b/]b - Fix conform double-setup by moving config to native nixvim settings - Fix cf to use conform instead of vim.lsp.buf.format - Fix ca to pass diagnostic context to code_action - Add nvim-lightbulb for code action indicator - Configure copilot Tab conflict: blink-cmp Tab=accept, C-n/p for cycling - Add completion.list.selection preselect for immediate Tab acceptance - Add TypeScript Japanese locale for LSP diagnostics Co-Authored-By: Claude Sonnet 4.6 --- modules/home/nixvim/default.nix | 20 --------- modules/home/nixvim/keymaps.nix | 27 ++++++++++-- modules/home/nixvim/lsp.nix | 1 + .../home/nixvim/plugins/editor/blink-cmp.nix | 23 +++++++++- .../home/nixvim/plugins/editor/conform.nix | 23 +++++++++- .../home/nixvim/plugins/editor/copilot.nix | 6 +++ .../home/nixvim/plugins/editor/telescope.nix | 43 ++----------------- modules/home/nixvim/plugins/ui/default.nix | 1 + modules/home/nixvim/plugins/ui/lightbulb.nix | 6 +++ 9 files changed, 84 insertions(+), 66 deletions(-) create mode 100644 modules/home/nixvim/plugins/ui/lightbulb.nix diff --git a/modules/home/nixvim/default.nix b/modules/home/nixvim/default.nix index 066bc74..6585c9a 100644 --- a/modules/home/nixvim/default.nix +++ b/modules/home/nixvim/default.nix @@ -40,25 +40,5 @@ nixd ]; - extraConfigLua = '' - require("conform").setup({ - formatters_by_ft = { - javascript = { "prettierd", "prettier", stop_after_first = true }, - javascriptreact = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - json = { "prettierd", "prettier", stop_after_first = true }, - yaml = { "prettierd", "prettier", stop_after_first = true }, - markdown = { "prettierd", "prettier", stop_after_first = true }, - lua = { "stylua" }, - nix = { "alejandra" }, - sh = { "shfmt" }, - }, - format_on_save = function(_) - return { timeout_ms = 1000, lsp_format = "fallback" } - end, - }) - - ''; }; } diff --git a/modules/home/nixvim/keymaps.nix b/modules/home/nixvim/keymaps.nix index f8be1c9..a3507bd 100644 --- a/modules/home/nixvim/keymaps.nix +++ b/modules/home/nixvim/keymaps.nix @@ -12,6 +12,7 @@ mode = "n"; key = key; action.__raw = raw; + options = { silent = true; desc = desc; @@ -24,7 +25,13 @@ in { (mkRaw "gd" "vim.lsp.buf.definition" "定義へ移動") (mkRaw "gr" "vim.lsp.buf.references" "参照を表示") (mkRaw "rn" "vim.lsp.buf.rename" "シンボル名を一括変換") - (mkRaw "cf" "vim.lsp.buf.format" "コードをフォーマット") + (mkRaw "cf" "function() require('conform').format({ timeout_ms = 1000, lsp_format = 'fallback' }) end" "コードをフォーマット") + (mkRaw "ca" "function() vim.lsp.buf.code_action({ context = { diagnostics = vim.diagnostic.get(0, { lnum = vim.fn.line('.') - 1 }) } }) end" "コードアクション") + + # Diagnostics + (mkRaw "]d" "vim.diagnostic.goto_next" "次のエラー") + (mkRaw "[d" "vim.diagnostic.goto_prev" "前のエラー") + (mkRaw "dl" "vim.diagnostic.open_float" "エラー詳細") # File tree (mk "e" "Neotree toggle left" "ファイルツリー") @@ -32,12 +39,24 @@ in { # Terminal (mk "tt" "ToggleTerm direction=float" "ターミナル") - # Diagnostics + # Diagnostics list (mk "xx" "Trouble diagnostics toggle" "エラー一覧") + # Window navigation + (mk "" "h" "左のウィンドウへ") + (mk "" "j" "下のウィンドウへ") + (mk "" "k" "上のウィンドウへ") + (mk "" "l" "右のウィンドウへ") + # Buffer Bar - (mk "bh" "BufferPrevious" "前のバッファーに移動") - (mk "bl" "BufferNext" "後のバッファーに移動") + (mk "[b" "BufferPrevious" "前のバッファーに移動") + (mk "]b" "BufferNext" "後のバッファーに移動") (mk "bc" "BufferClose" "バッファーを削除") + + # Telescope (explicit form for reliability) + (mkRaw "ff" "function() require('telescope.builtin').find_files() end" "ファイルを探す") + (mkRaw "fg" "function() require('telescope.builtin').live_grep() end" "文字列を全文検索") + (mkRaw "fb" "function() require('telescope.builtin').buffers() end" "開いているバッファを探す") + (mkRaw "fh" "function() require('telescope.builtin').help_tags() end" "ヘルプ項目を探す") ]; } diff --git a/modules/home/nixvim/lsp.nix b/modules/home/nixvim/lsp.nix index d843092..171ad5e 100644 --- a/modules/home/nixvim/lsp.nix +++ b/modules/home/nixvim/lsp.nix @@ -15,6 +15,7 @@ "jsconfig.json" ".git" ]; + extraOptions.settings.typescript.locale = "ja"; }; # Biome for lint / format diff --git a/modules/home/nixvim/plugins/editor/blink-cmp.nix b/modules/home/nixvim/plugins/editor/blink-cmp.nix index bbadc69..ba01396 100644 --- a/modules/home/nixvim/plugins/editor/blink-cmp.nix +++ b/modules/home/nixvim/plugins/editor/blink-cmp.nix @@ -12,8 +12,29 @@ "" = ["hide"]; "" = ["scroll_documentation_down"]; - "" = ["select_next" "fallback"]; + "" = [ + "accept" + { + __raw = '' + function() + local ok, copilot = pcall(require, "copilot.suggestion") + if ok and copilot.is_visible() then + copilot.accept() + return true + end + end + ''; + } + "fallback" + ]; "" = ["select_prev" "fallback"]; + "" = ["select_next" "fallback"]; + "" = ["select_prev" "fallback"]; + }; + + completion.list.selection = { + preselect = true; + auto_insert = false; }; sources.default = [ diff --git a/modules/home/nixvim/plugins/editor/conform.nix b/modules/home/nixvim/plugins/editor/conform.nix index 25e27f5..e451b4b 100644 --- a/modules/home/nixvim/plugins/editor/conform.nix +++ b/modules/home/nixvim/plugins/editor/conform.nix @@ -1,3 +1,24 @@ {...}: { - programs.nixvim.plugins."conform-nvim".enable = true; + programs.nixvim.plugins."conform-nvim" = { + enable = true; + settings = { + formatters_by_ft = { + javascript.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + javascriptreact.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + typescript.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + typescriptreact.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + json.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + yaml.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + markdown.__raw = ''{ "prettierd", "prettier", stop_after_first = true }''; + lua = ["stylua"]; + nix = ["alejandra"]; + sh = ["shfmt"]; + }; + format_on_save.__raw = '' + function(_) + return { timeout_ms = 1000, lsp_format = "fallback" } + end + ''; + }; + }; } diff --git a/modules/home/nixvim/plugins/editor/copilot.nix b/modules/home/nixvim/plugins/editor/copilot.nix index 5bb9f11..783bfd1 100644 --- a/modules/home/nixvim/plugins/editor/copilot.nix +++ b/modules/home/nixvim/plugins/editor/copilot.nix @@ -1,5 +1,11 @@ {...}: { programs.nixvim.plugins.copilot-lua = { enable = true; + settings = { + suggestion = { + auto_trigger = true; + keymap.enabled = false; + }; + }; }; } diff --git a/modules/home/nixvim/plugins/editor/telescope.nix b/modules/home/nixvim/plugins/editor/telescope.nix index b530186..17f02c3 100644 --- a/modules/home/nixvim/plugins/editor/telescope.nix +++ b/modules/home/nixvim/plugins/editor/telescope.nix @@ -1,43 +1,6 @@ {...}: { - programs.nixvim = { - plugins.telescope = { - enable = true; - extensions = { - fzf-native.enable = true; - }; - keymaps = { - "ff" = { - action = "find_files"; - options = { - desc = "ファイルを探す"; - silent = true; - }; - }; - - "fg" = { - action = "live_grep"; - options = { - desc = "文字列を全文検索"; - silent = true; - }; - }; - - "fb" = { - action = "buffers"; - options = { - desc = "開いているバッファを探す"; - silent = true; - }; - }; - - "fh" = { - action = "help_tags"; - options = { - desc = "ヘルプ項目を探す"; - silent = true; - }; - }; - }; - }; + programs.nixvim.plugins.telescope = { + enable = true; + extensions.fzf-native.enable = true; }; } diff --git a/modules/home/nixvim/plugins/ui/default.nix b/modules/home/nixvim/plugins/ui/default.nix index cda580f..ed3903b 100644 --- a/modules/home/nixvim/plugins/ui/default.nix +++ b/modules/home/nixvim/plugins/ui/default.nix @@ -8,5 +8,6 @@ ./toggleterm.nix ./treesitter.nix ./barbar.nix + ./lightbulb.nix ]; } diff --git a/modules/home/nixvim/plugins/ui/lightbulb.nix b/modules/home/nixvim/plugins/ui/lightbulb.nix new file mode 100644 index 0000000..f862079 --- /dev/null +++ b/modules/home/nixvim/plugins/ui/lightbulb.nix @@ -0,0 +1,6 @@ +{...}: { + programs.nixvim.plugins.nvim-lightbulb = { + enable = true; + settings.autocmd.enabled = true; + }; +}