fix(api): nvim_parse_cmd parses :map incorrectly #34068

Problem: nvim_parse_cmd() incorrectly splits mapping commands like
into three arguments instead of preserving whitespace in the RHS.

Solution: Add special handling for mapping commands to parse them as exactly
two arguments - the LHS and the RHS with all whitespace preserved.
This commit is contained in:
glepnir
2025-06-15 01:17:56 +08:00
committed by GitHub
parent 4367441213
commit c7f38e3bc8
3 changed files with 89 additions and 3 deletions

View File

@ -4641,6 +4641,45 @@ describe('API', function()
},
}, api.nvim_parse_cmd('argadd a.txt | argadd b.txt', {}))
end)
it('parses :map commands with space in RHS', function()
eq({
addr = 'none',
args = { 'a', 'b c' },
bang = false,
cmd = 'map',
magic = {
bar = true,
file = false,
},
mods = {
browse = false,
confirm = false,
emsg_silent = false,
filter = {
force = false,
pattern = '',
},
hide = false,
horizontal = false,
keepalt = false,
keepjumps = false,
keepmarks = false,
keeppatterns = false,
lockmarks = false,
noautocmd = false,
noswapfile = false,
sandbox = false,
silent = false,
split = '',
tab = -1,
unsilent = false,
verbose = -1,
vertical = false,
},
nargs = '*',
nextcmd = '',
}, api.nvim_parse_cmd('map a b c', {}))
end)
it('works for nargs=1', function()
command('command -nargs=1 MyCommand echo <q-args>')
eq({