mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #16591 from shadmansaleh/feat/lua_keymaps2
feat(lua): add support for lua keymaps
This commit is contained in:
@@ -2298,3 +2298,82 @@ describe('lua: require("mod") from packages', function()
|
||||
eq('I am fancy_z.lua', exec_lua [[ return require'fancy_z' ]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('vim.keymap', function()
|
||||
it('can make a mapping', function()
|
||||
eq(0, exec_lua [[
|
||||
GlobalCount = 0
|
||||
vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end)
|
||||
return GlobalCount
|
||||
]])
|
||||
|
||||
feed('asdf\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
end)
|
||||
|
||||
it('can make an expr mapping', function()
|
||||
exec_lua [[
|
||||
vim.keymap.set('n', 'aa', function() return ':lua SomeValue = 99<cr>' end, {expr = true})
|
||||
]]
|
||||
|
||||
feed('aa')
|
||||
|
||||
eq(99, exec_lua[[return SomeValue]])
|
||||
end)
|
||||
|
||||
it('can overwrite a mapping', function()
|
||||
eq(0, exec_lua [[
|
||||
GlobalCount = 0
|
||||
vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end)
|
||||
return GlobalCount
|
||||
]])
|
||||
|
||||
feed('asdf\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
|
||||
exec_lua [[
|
||||
vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount - 1 end)
|
||||
]]
|
||||
|
||||
feed('asdf\n')
|
||||
|
||||
eq(0, exec_lua[[return GlobalCount]])
|
||||
end)
|
||||
|
||||
it('can unmap a mapping', function()
|
||||
eq(0, exec_lua [[
|
||||
GlobalCount = 0
|
||||
vim.keymap.set('n', 'asdf', function() GlobalCount = GlobalCount + 1 end)
|
||||
return GlobalCount
|
||||
]])
|
||||
|
||||
feed('asdf\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
|
||||
exec_lua [[
|
||||
vim.keymap.del('n', 'asdf')
|
||||
]]
|
||||
|
||||
feed('asdf\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
eq('\nNo mapping found', helpers.exec_capture('nmap asdf'))
|
||||
end)
|
||||
|
||||
it('can do <Plug> mappings', function()
|
||||
eq(0, exec_lua [[
|
||||
GlobalCount = 0
|
||||
vim.keymap.set('n', '<plug>(asdf)', function() GlobalCount = GlobalCount + 1 end)
|
||||
vim.keymap.set('n', 'ww', '<plug>(asdf)')
|
||||
return GlobalCount
|
||||
]])
|
||||
|
||||
feed('ww\n')
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user