aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/keymap_spec.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-05-28 12:09:52 +0200
committerbfredl <bjorn.linse@gmail.com>2023-06-09 21:25:43 +0200
commit42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59 (patch)
treedbb621867adf58beac42647e3e6267e55521909e /test/functional/api/keymap_spec.lua
parent49019da86e283052c042509689f3a287056d1340 (diff)
downloadrneovim-42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59.tar.gz
rneovim-42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59.tar.bz2
rneovim-42bbc4fabcf948ac6b8798b8992bcba1fc1d3e59.zip
feat(api): support abbreviations in nvim_set_keymap
closes #19198
Diffstat (limited to 'test/functional/api/keymap_spec.lua')
-rw-r--r--test/functional/api/keymap_spec.lua48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua
index e239717d3a..e56dfd483a 100644
--- a/test/functional/api/keymap_spec.lua
+++ b/test/functional/api/keymap_spec.lua
@@ -988,6 +988,54 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
eq("\nn lhs rhs\n map description",
helpers.exec_capture("nmap lhs"))
end)
+
+ it('can define !-mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('!a', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The 1 and the bar and the 2 again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The 3 is the one', meths.eval'x')
+ end)
+
+ it('can define insert mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('ia', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The 1 and the bar and the 2 again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The foo is the one', meths.eval'x')
+ end)
+
+ it('can define cmdline mode abbreviations with lua callbacks', function()
+ exec_lua [[
+ GlobalCount = 0
+ vim.api.nvim_set_keymap('ca', 'foo', '', {expr = true, callback = function()
+ GlobalCount = GlobalCount + 1
+ return tostring(GlobalCount)
+ end})
+ ]]
+
+ feed 'iThe foo and the bar and the foo again<esc>'
+ eq('The foo and the bar and the foo again', meths.get_current_line())
+
+ feed ':let x = "The foo is the one"<cr>'
+ eq('The 1 is the one', meths.eval'x')
+ end)
end)
describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()