Thanslate a vimscript code to lua
I have a plugin called Beacon installed, basicle:
Whenever cursor jumps some distance or moves between windows, it will flash so you can see where it is. This plugin is heavily inspired by emacs package beacon.
Some of suggested mappings are (using my map-helper function):
-- map helper
local function map(mode, lhs, rhs, opts)
local options = { noremap = true }
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
map('n', 'n', 'n:Beacon<cr>')
map('n', 'N', 'N:Beacon<cr>')
map('n', '*', '*:Beacon<cr>')
map('n', '#', '#:Beacon<cr>')
With no mappings, when I press n I can see the search count in the status bar, something like: [3/8]
.
I have found a vimscript solution that goes like this:
function! AppendMap(name, mode, rhs)
let l:oldrhs = maparg(a:name, a:mode)
exe printf('%smap %s %s', a:mode, a:name, l:oldrhs.a:rhs)
endf
call AppendMap('n', 'n', ':echo "detected"<CR>')
" If key 'n' was mapped to 'nzz', then it is now mapped to 'nzz:echo "detected"<CR>'