From 93a4a934eb87f39a971bfd46efa35f5698a11eff Mon Sep 17 00:00:00 2001 From: Daniel Fainberg Date: Tue, 15 Sep 2026 12:45:55 +0200 Subject: [PATCH] feat(nvim): accept completion with ``, indent 4 blink.cmp uses the `enter` preset with `completion.list.selection.preselect = false`, so an item is taken only once selected with ``/`` and `` otherwise inserts a newline. `` stays bound as vim's own confirm key. `` and `` both run `cancel` rather than the preset's `hide`: hiding leaves the auto_insert preview in the buffer without the `additionalTextEdits` and snippet expansion a real accept applies, and builtin ins-completion `` likewise restores the typed text. `shiftwidth`/`tabstop` are 4, matching PHP's PSR-12. PHP's `indentkeys` carry `*`, which reindents the just-finished line on every newline; at width 2 that silently re-indented 4-space files. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015D4NsszUG7hy9ghKZ4nfhm --- modules/nvim.nix | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/nvim.nix b/modules/nvim.nix index cc0d59c..1fbdaa0 100644 --- a/modules/nvim.nix +++ b/modules/nvim.nix @@ -86,8 +86,8 @@ in scrolloff = 8; # keep 8 lines of context around the cursor expandtab = true; # spaces, not tabs - shiftwidth = 2; - tabstop = 2; + shiftwidth = 4; + tabstop = 4; smartindent = true; ignorecase = true; # case-insensitive search… @@ -162,10 +162,31 @@ in blink-cmp = { enable = true; settings = { - keymap.preset = "default"; # C-space open, C-y confirm, C-n/C-p move + # "enter" preset: accepts, Up/Down and C-n/C-p move, Tab is + # left to snippet jumping. Custom keys below merge over the preset. + keymap = { + preset = "enter"; + # Vim's own ins-completion confirm key, kept alongside . + "" = [ "select_and_accept" "fallback" ]; + # Dismiss the menu and undo the auto_insert preview, staying in + # insert mode. `cancel` rather than the preset's `hide`, which + # would leave the previewed text in the buffer without the + # additionalTextEdits (imports) and snippet expansion that a real + # accept applies — a degraded accept nobody wants. This also + # matches builtin ins-completion, where C-e restores the typed + # text. With no menu open both keys fall back to their native + # meaning (Esc leaves insert mode). + "" = [ "cancel" "fallback" ]; + "" = [ "cancel" "fallback" ]; + }; appearance.nerd_font_variant = "mono"; sources.default = [ "lsp" "path" "snippets" "buffer" ]; - completion.documentation.auto_show = true; + completion = { + documentation.auto_show = true; + # No item is selected until one is picked with Down/C-n, so + # inserts a newline unless a completion was deliberately chosen. + list.selection.preselect = false; + }; }; };