neovim: slice 2 plugins — which-key, gitsigns, oil, nvim-ufo, direnv (#19) #25

Merged
rpickler merged 5 commits from issue-19-nixvim-slice-2-plugins into main 2026-10-17 04:54:51 +00:00
Member

Implements the slice-2 proposal from issue #19 (comment id 441) — the five plugins rpickler named, for testing. Follows #21 which merged.

New files under users/modules/neovim/plugins/ (all option names verified against the nixvim rev pinned in flake.lock, 5b912bd8):

  • which-key.nix — bare enable; auto-labels the slice-1 gd/gr/<leader>ca… keymaps via their desc.
  • gitsigns.nix — enable + keymaps: ]c/[c hunk nav, <leader>gs stage, <leader>gr reset, <leader>gp preview, <leader>gb blame. current_line_blame left off for now (on-demand blame via <leader>gb).
  • oil.nix — oil as default file explorer (default_file_explorer = true), columns permissions/icon/size/type/git, <leader>e → :Oil --float, <leader>E → :Oil. Plus oil-git-status for git markers (its module sets the required win_options.signcolumn = "yes:2" default itself).
  • nvim-ufo.nix — folds: opts.foldmethod = "expr" + foldexpr = "v:lua.vim.ufo.foldexpr()", unfolded at start (foldenable = false, foldlevel = 99, foldcolumn = "1"); provider_selector with nix/vim = "indent" fallbacks; zR/zM/zr/zm/zp ufo keymaps. Module's setupLspCapabilities stays on (wires LSP foldingRange).
  • direnv.nix — auto = 1, silent_load = 1, edit_mode = "edit" (the by-name module wraps direnv-vim; 0/1 flags).

Edits to existing files:

  • plugins/default.nix — imports the five new modules.
  • plugins/snacks/default.nix — foldnav.enabled = false: snacks' zA/zo/zc/zR… keymaps overlap ufo's; ufo's README asks other fold plugins to release them.
  • default.nix — direnv CLI added to extraPackages (the module pulls the Vim plugin but not the binary :DirenvExport needs).

Deliberately not included, per your feedback: conform/format-on-save, smear-cursor, nabla, yanky. Formatting stays manual via <leader>cf.

Note: oil's own <C-h> insert-mode mapping is left at its default (parent-dir) — didn't override it. Not build-verified from my side (no nix here); your rebuild is the real test. If foldcolumn = "1" bugs you, delete that one line in nvim-ufo.nix.

Closes #19? No — keeping #19 open for future slices per the thread.

Implements the slice-2 proposal from issue #19 (comment id 441) — the five plugins rpickler named, for testing. Follows #21 which merged. **New files under `users/modules/neovim/plugins/`** (all option names verified against the nixvim rev pinned in `flake.lock`, `5b912bd8`): - **`which-key.nix`** — bare enable; auto-labels the slice-1 `gd`/`gr`/`<leader>ca`… keymaps via their `desc`. - **`gitsigns.nix`** — enable + keymaps: `]c`/`[c` hunk nav, `<leader>gs` stage, `<leader>gr` reset, `<leader>gp` preview, `<leader>gb` blame. `current_line_blame` left off for now (on-demand blame via `<leader>gb`). - **`oil.nix`** — oil as default file explorer (`default_file_explorer = true`), columns `permissions/icon/size/type/git`, `<leader>e` → `:Oil --float`, `<leader>E` → `:Oil`. Plus `oil-git-status` for git markers (its module sets the required `win_options.signcolumn = "yes:2"` default itself). - **`nvim-ufo.nix`** — folds: `opts.foldmethod = "expr"` + `foldexpr = "v:lua.vim.ufo.foldexpr()"`, unfolded at start (`foldenable = false`, `foldlevel = 99`, `foldcolumn = "1"`); `provider_selector` with `nix`/`vim = "indent"` fallbacks; `zR`/`zM`/`zr`/`zm`/`zp` ufo keymaps. Module's `setupLspCapabilities` stays on (wires LSP foldingRange). - **`direnv.nix`** — `auto = 1`, `silent_load = 1`, `edit_mode = "edit"` (the by-name module wraps direnv-vim; 0/1 flags). **Edits to existing files:** - `plugins/default.nix` — imports the five new modules. - `plugins/snacks/default.nix` — `foldnav.enabled = false`: snacks' `zA`/`zo`/`zc`/`zR`… keymaps overlap ufo's; ufo's README asks other fold plugins to release them. - `default.nix` — `direnv` CLI added to `extraPackages` (the module pulls the Vim plugin but not the binary `:DirenvExport` needs). Deliberately **not** included, per your feedback: conform/format-on-save, smear-cursor, nabla, yanky. Formatting stays manual via `<leader>cf`. Note: oil's own `<C-h>` insert-mode mapping is left at its default (parent-dir) — didn't override it. Not build-verified from my side (no nix here); your rebuild is the real test. If `foldcolumn = "1"` bugs you, delete that one line in `nvim-ufo.nix`. Closes #19? No — keeping #19 open for future slices per the thread.
Per the slice-2 proposal (issue #19 comment): the five plugins rpickler
named, wired against the nixvim rev pinned in flake.lock (5b912bd8).

- which-key: bare enable; labels the slice-1 LSP keymaps automatically
- gitsigns: enable + hunk nav/stage/reset/preview/blame keymaps
- oil + oil-git-status: default file explorer, <leader>e float /
  <leader>E fullscreen; git markers in the listing
- nvim-ufo: fold opts (foldexpr via ufo, unfolded at start) + ufo
  keymaps; snacks' foldnav keymaps disabled to release the z* mappings
- direnv: auto/silent export via direnv-vim; direnv CLI added to
  extraPackages (the module only pulls the Vim plugin)

Held back per feedback: conform/format-on-save, smear-cursor, nabla,
yanky.
@ -0,0 +10,4 @@
settings = {
# nix has no reliable lsp/treesitter folding ranges — indent is the
# plugin README's fallback for such filetypes.
provider_selector.__raw = ''
Owner

Something wrong with this function:

init.lua> error: could not format file /nix/store/0n7hif0zw98a5yqj4m86vfaq7qkv6rnp-init.lua: error parsing:
init.lua>  - unexpected token `[` (88:3 to 88:52), expected `end` to close function body block
init.lua>  - unexpected token `[` (88:54 to 88:55), expected `}` after last field
init.lua>  - unexpected token `(` (87:21 to 87:22), expected `)` to close function call
init.lua>  - unexpected token `end` (89:1 to 89:4), unexpected expression when looking for a statement
init.lua>  - unexpected token `end` (89:1 to 89:4), unexpected token, this needs to be a statement
Something wrong with this function: ``` init.lua> error: could not format file /nix/store/0n7hif0zw98a5yqj4m86vfaq7qkv6rnp-init.lua: error parsing: init.lua> - unexpected token `[` (88:3 to 88:52), expected `end` to close function body block init.lua> - unexpected token `[` (88:54 to 88:55), expected `}` after last field init.lua> - unexpected token `(` (87:21 to 87:22), expected `)` to close function call init.lua> - unexpected token `end` (89:1 to 89:4), unexpected expression when looking for a statement init.lua> - unexpected token `end` (89:1 to 89:4), unexpected token, this needs to be a statement ```
@ -0,0 +11,4 @@
};
keymaps = [
{
Owner

These first two keymaps are causing errors when starting neovim.

These first two keymaps are causing errors when starting neovim.
Lua's prefixexp grammar does not allow subscripting a table literal
directly: 'return { ... }[filetype]' fails to compile ('end expected ...
near ['), which is what broke init.lua (luap error at 88:3).
Bind the map to a local first, then index it — the pattern from the
plugin's README. Verified against the Lua 5.1 reference parser
('end expected near [' on the old form, clean compile on the new one);
runtime behaviour is unchanged (nix/vim -> indent, git -> '',
others -> nil).
Author
Member

Fixed in 0e383f6 — you were right, the function itself was broken.

Root cause: Lua's grammar does not allow indexing a table constructor inline. return { nix = "indent", ... }[filetype] is not a valid expression (prefixexp can't be a { ... } literal followed by a subscript), so the parser aborts at the [, gives up trying to close the return, and cascades into the expected end/expected } errors you saw. The plugin README uses a bound local for exactly this reason; my one-liner shortcut was the bug.

Fix (matches the README pattern):

function(bufnr, filetype, buftype)
  local ftMap = { nix = "indent", vim = "indent", git = "" }
  return ftMap[filetype]
end

Verified: compiled both forms against the Lua 5.1 reference parser — the old form fails with 'end' expected (to close 'function') near '[' (same failure as your init.lua error), the new form compiles clean. Runtime behaviour is unchanged: nix/vim → "indent", git → "", other filetypes → nil (ufo falls through to its default providers).

Also swept the rest of the slice for the same pattern — the only other __raw Lua in these files are bare require('ufo').* / require('gitsigns').* references, no inline-subscript constructs anywhere else.

Fixed in 0e383f6 — you were right, the function itself was broken. **Root cause:** Lua's grammar does not allow indexing a table constructor inline. `return { nix = "indent", ... }[filetype]` is not a valid expression (`prefixexp` can't be a `{ ... }` literal followed by a subscript), so the parser aborts at the `[`, gives up trying to close the `return`, and cascades into the `expected end`/`expected }` errors you saw. The plugin README uses a bound local for exactly this reason; my one-liner shortcut was the bug. **Fix** (matches the README pattern): ```lua function(bufnr, filetype, buftype) local ftMap = { nix = "indent", vim = "indent", git = "" } return ftMap[filetype] end ``` **Verified:** compiled both forms against the Lua 5.1 reference parser — the old form fails with `'end' expected (to close 'function') near '['` (same failure as your init.lua error), the new form compiles clean. Runtime behaviour is unchanged: `nix`/`vim` → `"indent"`, `git` → `""`, other filetypes → `nil` (ufo falls through to its default providers). Also swept the rest of the slice for the same pattern — the only other `__raw` Lua in these files are bare `require('ufo').*` / `require('gitsigns').*` references, no inline-subscript constructs anywhere else.
X-Hermes-Session-Id is now a function evaluated by CodeCompanion on
every request (set_env_vars evaluates function header values), so the
id tracks repo/branch switches without an autocmd. Outside a git repo
it falls back to the old cwd-name behaviour.

Also refactor codecompanion (plugin config + keymaps) out of
users/modules/neovim/default.nix into plugins/codecompanion.nix,
matching how telescope/lsp/cmp are defined.
rpickler deleted branch issue-19-nixvim-slice-2-plugins 2026-10-17 04:54:52 +00:00
Author
Member

Closing the loop: PR is merged with both review points settled.

  • nvim-ufo provider_selector (review on nvim-ufo.nix): fixed in 0e383f6 — the bound-local ftMap form from the plugin README; merged as-is on main.
  • gitsigns ]c/[c keymaps (review on gitsigns.nix): settled by 87a65911 — left commented out on main (and kept commented out on the slice-3 branch in PR #28), so startup is clean and gitsigns keeps its own default nav maps.

Nothing outstanding on this PR.

Closing the loop: PR is merged with both review points settled. - **nvim-ufo `provider_selector`** (review on `nvim-ufo.nix`): fixed in 0e383f6 — the bound-local `ftMap` form from the plugin README; merged as-is on main. - **gitsigns `]c`/`[c` keymaps** (review on `gitsigns.nix`): settled by 87a65911 — left commented out on main (and kept commented out on the slice-3 branch in PR #28), so startup is clean and gitsigns keeps its own default nav maps. Nothing outstanding on this PR.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
richardpickler.com/nixos!25
No description provided.