tree-sitter-vim-map-side
v0.1.3
Published
Vim's map side (lhs and rhs) grammar for tree-sitter
Maintainers
Readme
tree-sitter-vim-map-side
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 tolshandrhsof keymap functions of neovimprintf(optional): injection to first argument ofprintf()expression.vim(optional): injection torhswhen it starts with:and tocommandnodes of this grammar.
Usage in Editors
Neovim
- vim-map-side.nvim: plugin
that integrates this grammar to your
Neovimconfiguration.
Helix
WIP
Emacs
WIP
Injections
[!NOTE] If you are using Neovim, you can use
lua-match?andnot-lua-match?predicates instead ofmatch?andnot-match?. Be sure to use%sinstead of\sand%Sinstead of\Sin 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"))