From f3ec657ebc02e8fb68e7cf46213333932325fe2f Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 13 Mar 2026 18:06:39 +0800 Subject: fix(api): nvim_parse_cmd on range-only, modifier-only commands #36665 Problem: nvim_parse_cmd rejects valid commands like `:1` (range-only) or `aboveleft` (modifier-only). Solution: allow empty command when range or modifiers exist, and handle execution using existing range command logic. --- test/functional/api/vim_spec.lua | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 196165ea90..d69c99b61b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4979,6 +4979,66 @@ describe('API', function() result = api.nvim_parse_cmd('copen 5', {}) eq(5, result.count) end) + it('parses range-only command', function() + insert [[ + line1 + line2 + line3 + line4 + ]] + api.nvim_win_set_cursor(0, { 4, 4 }) + local res = api.nvim_parse_cmd('1', {}) + eq({ + addr = 'line', + args = {}, + bang = false, + cmd = '', + magic = { + bar = false, + 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 = '0', + nextcmd = '', + range = { 1 }, + }, res) + api.nvim_cmd(res, {}) + eq(1, api.nvim_win_get_cursor(0)[1]) + feed('VG:') + n.poke_eventloop() + res = api.nvim_parse_cmd("'<,'>", {}) + eq({ 1, 5 }, res.range) + end) + it('parses modifier-only command', function() + local res = api.nvim_parse_cmd('aboveleft', {}) + eq('', res.cmd) + eq('aboveleft', res.mods.split) + eq('none', res.addr) + end) end) describe('nvim_cmd', function() @@ -5209,6 +5269,9 @@ describe('API', function() -- error from the next command typed is not suppressed #21420 feed(':call') eq('E471: Argument required', api.nvim_cmd({ cmd = 'messages' }, { output = true })) + + -- modifier only + eq('', api.nvim_cmd({ cmd = '', mods = { noautocmd = true } }, {})) end) it('works with magic.file', function() -- cgit