tree-sitter-vim-map-side

Crates.iotree-sitter-vim-map-side
lib.rstree-sitter-vim-map-side
version0.1.3
created_at2025-10-28 23:44:59.293081+00
updated_at2025-10-28 23:44:59.293081+00
descriptionVim's map side (lhs and rhs) grammar for tree-sitter
homepage
repositoryhttps://github.com/hdoc1509/tree-sitter-vim-map-side
max_upload_size
id1905774
size101,564
Héctor Ochoa (Hdoc1509)

documentation

README

tree-sitter-vim-map-side

CI discord matrix crates npm pypi

Vim's map side (lhs and rhs) grammar for tree-sitter.

Primaryly intended to be used within lua, but also supports vim mappings with rhs that starts with : (not supported at the moment).

[!IMPORTANT] ABI version: 15

Supported rhs expressions

  • printf()
  • variable-scope: g:, l:, v:

[!NOTE] More expressions will be supported in the future if requested.

Parser requirements

  • lua: injection to lsh and rhs of keymap functions of neovim
  • printf (optional): injection to first argument of printf() expression.
  • vim (optional): injection to rhs when it starts with : and to command nodes of this grammar.

Usage in Editors

Neovim

  • vim-map-side.nvim: plugin that integrates this grammar to your Neovim configuration.

Helix

WIP

Emacs

WIP

Injections

[!NOTE] If you are using Neovim, you can use lua-match? and not-lua-match? predicates instead of match? and not-match?. Be sure to use %s instead of \s and %S instead of \S in the regexes.

lua parser

For vim.keymap.set(), vim.api.nvim_set_keymap() and vim.api.nvim_buf_set_keymap() functions of neovim:

; NOTE: for lhs and rhs
(function_call
  name: (_) @_fn
  arguments: [
    ; format-ignore
    (arguments
      . (_) ; -- mode --
      .
      (string
        (string_content) @injection.content))
    ; format-ignore
    (arguments
      . (_) ; -- mode --
      . (_) ; -- lhs --
      (string
        (string_content) @injection.content))
  ]
  (#any-of? @_fn "vim.keymap.set" "vim.api.nvim_set_keymap")
  (#match? @injection.content "<\S+>")
  (#set! injection.language "vim_map_side"))

(function_call
  name: (_) @_fn
  arguments: [
    ; format-ignore
    (arguments
      . (_) ; -- buffer --
      . (_) ; -- mode --
      .
      (string
        (string_content) @injeciton.content))
    ; format-ignore
    (arguments
      . (_) ; -- buffer --
      . (_) ; -- mode --
      . (_) ; -- lhs --
      .
      (string
        (string_content) @injeciton.content))
  ]
  (#eq? @_fn "vim.api.nvim_buf_set_keymap")
  (#match? @injeciton.content "<\S+>")
  (#set! injection.language "vim_map_side"))

; NOTE: for expressions as rhs
(function_call
  name: (_) @_fn
  ; format-ignore
  arguments: (arguments
    . (_) ; -- mode --
    . (_) ; -- lhs --
    .
    (string
      (string_content) @injection.content)
    .
    (table_constructor) @_options)
  (#any-of? @_fn "vim.keymap.set" "vim.api.nvim_set_keymap")
  ; NOTE: to avoid double injection
  (#not-match? @injection.content "<\S+>")
  (#match? @_options "expr\s*=\s*true")
  (#set! injection.language "vim_map_side"))

(function_call
  name: (_) @_fn
  ; format-ignore
  arguments: (arguments
    . (_) ; -- buffer --
    . (_) ; -- mode --
    . (_) ; -- lhs --
    .
    (string
      (string_content) @injection.content)
    .
    (table_constructor) @_options)
  (#eq? @_fn "vim.api.nvim_buf_set_keymap")
  ; NOTE: to avoid double injection
  (#not-match? @injection.content "<\S+>")
  (#match? @_options "expr\s*=\s*true")
  (#set! injection.language "vim_map_side"))

vim parser

(map_statement
  rhs: (map_side) @injection.content
  (#match? @injection.content "^:")
  (#set! injection.include-children)
  (#set! injection.language "vim_map_side"))

References

Commit count: 0

cargo fmt