nvim-libmodal/examples/lua/layer.lua
Iron-E afdfadf365
ref: use Neovim 0.5
BREAKING CHANGE: now requires Neovim 0.5
2021-07-07 14:25:53 -04:00

41 lines
1.0 KiB
Lua

-- Imports
local libmodal = require('libmodal')
-- create a new layer.
local layer = libmodal.Layer.new({
n = { -- normal mode mappings
gg = { -- remap `gg`
rhs = 'G', -- map it to `G`
noremap = true, -- don't recursively map.
},
G = { -- remap `G`
rhs = 'gg', -- map it to `gg`
noremap = true -- don't recursively map.
}
}
})
-- enter the `layer`.
layer:enter()
-- add a global function for exiting the mode.
function LibmodalLayerExampleExit()
layer:exit()
end
-- Add an additional mapping for `z`.
layer:map('n', 'z', 'gg', {noremap = true})
-- add an additional mapping for `q`.
layer:map(
'n', 'q', ':lua LibmodalLayerExampleExit()<CR>',
{noremap = true, silent = true}
)
--[[ unmap `gg` and `G`. Notice they both return to their defaults,
rather than just not doing anything anymore. ]]
layer:unmap('n', 'gg')
layer:unmap('n', 'G')
-- If you wish to only change the mappings of a layer temporarily, you should use another layer. `map` and `unmap` permanently add and remove from the layer's keymap.