Skip to content

mappings: add ft option for filetype-scoped keymaps - #1814

Open
theol-git wants to merge 4 commits into
NotAShelf:mainfrom
theol-git:feature/filetype-keymaps
Open

theol-git wants to merge 4 commits into
NotAShelf:mainfrom
theol-git:feature/filetype-keymaps

Conversation

@theol-git

Copy link
Copy Markdown

Aim

Adds an ft option to vim.keymaps, so a keymap can be scoped to specific
filetypes while keeping the configuration declarative inside vim.keymaps.

Today vim.keymaps only emits global mappings. With ft, nvf instead generates
a FileType autocmd that creates a buffer-local mapping whenever a buffer of one
of the given filetypes is opened. ft defaults to an empty list, which keeps the
mapping global. This is not lazy loading — it only makes keymaps active for
specific filetypes.

Example:

vim.keymaps = [
  {
    mode = "n";
    key = "<leader>p";
    action = "<cmd>Git push<CR>";
    desc = "Push commit";
    ft = [ "fugitive" ];
  }
];

generates:

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "fugitive" },
  callback = function()
    vim.keymap.set("n", "<leader>p", "<cmd>Git push<CR>", {
      buffer = true,
      desc = "Push commit",
    })
  end,
})

Testing

  • Verified the generated Lua through module evaluation
    (config.vim.builtLuaConfigRC) for global, ft = [...], and ft = [] cases.
  • Tested in a real nvf build using a filetype-scoped keymap; confirmed the buffer-local mapping appears only on buffers of the matching filetype.
  • Built .#nix, .#maximal, and .#docs-html successfully.

Sanity Checking

  • I have updated the changelog as per my changes
  • I have tested, and self-reviewed my code
  • My changes fit guidelines found in hacking nvf
  • Style and consistency
    • I ran Alejandra to format my code (nix fmt)
    • My code conforms to the editorconfig configuration of the project
    • My changes are consistent with the rest of the codebase
  • If new changes are particularly complex:
    • [N/A] My code includes comments in particularly complex areas
    • I have added a section in the manual
    • [N/A] (For breaking changes) I have included a migration guide
  • Package(s) built:
    • .#nix (default package)
    • .#maximal
    • .#docs-html (manual, must build)
    • [N/A] .#docs-linkcheck (optional, please build if adding links)
  • Tested on platform(s)
    • x86_64-linux
    • [] aarch64-linux
    • [] x86_64-darwin
    • [] aarch64-darwin

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

🚀 Live preview deployed from 5e4f212

View it here:

Debug Information

Triggered by: theol-git

HEAD at: feature/filetype-keymaps

Reruns: 4049

github-actions Bot pushed a commit that referenced this pull request Sep 4, 2026
github-actions Bot pushed a commit that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant