A tiny utility to call any *map commands.
In Vimscript, we can do this.
nmap <C-u> :echo 'Hello, World!'<CR>
imap <C-t> <buffer> <expr> strftime('%FT%T') In addition to this, Neovim has two functions for Lua -- nvim_set_keymap, nvim_buf_set_keymap --, and they are so annoying.
vim.api.nvim_set_keymap('n', '<C-u>', [[:echo 'Hello, World!']], {})
vim.api.nvim_buf_set_keymap(0, '<C-t>', [[strftime('%FT%T')]], {expr = true})Too complex and too long syntax. mappy.nvim solves this.
local mappy = require'mappy'
mappy.nmap('<C-u>', [[:echo 'Hello, World!']])
mappy.imap({'expr', 'buffer'}, [[strftime('%FT%T')]])So simple!
mappy.nvim supplies functions below.
All functions
| mappy.nvim | equivalent in Vimscript |
|---|---|
map | map |
map_ | map! |
nmap | nmap |
vmap | vmap |
xmap | xmap |
smap | smap |
omap | omap |
imap | imap |
lmap | lmap |
cmap | cmap |
tmap | tmap |
noremap | noremap |
noremap_ | noremap! |
nnoremap | nnoremap |
vnoremap | vnoremap |
xnoremap | xnoremap |
snoremap | snoremap |
onoremap | onoremap |
inoremap | inoremap |
lnoremap | lnoremap |
cnoremap | cnoremap |
tnoremap | tnoremap |
unmap | unmap |
unmap_ | unmap! |
nunmap | nunmap |
vunmap | vunmap |
xunmap | xunmap |
sunmap | sunmap |
ounmap | ounmap |
iunmap | iunmap |
lunmap | lunmap |
cunmap | cunmap |
tunmap | tunmap |
Names of functions are almost the same as Vimscript's ones. An exception for this exists. It is map! (and noremap!, unmap!) -- in mappy.nvim, you can use map_ (and noremap_, unmap_) for that.
mappy.nvim can map keys to Lua functions! This cannot do with the original nvim_set_keymap, nvim_buf_set_keymap.
mappy.imap({'buffer'}, '<C-t>', function()
print'Hello, World!'
end)Lua functions cannot be mapped to <expr> mappings.
You can use bind() for this.
mappy.bind('nit', {'buffer'}, '<A-t>', function()
print(os.date('%FT%T'))
end)This can call the function with <A-t> in normal, insert, and terminal modes.
bind() does mappings with noremap = true. You can use recursive mappings with rbind().
mappy.rbind('nv', {'buffer'}, '<C-t>', 'n')add_buffer_maps() calls functions to run mappy with {'buffer'}.
mappy.add_buffer_maps(function()
mappy.imap({'expr'}, '<C-t>', [[strftime("%FT%T")]])
end)This adds {'buffer'} and call nvim_buf_set_keymap automatically.
- svermeulen/vimpeccable
- Actually, this plugin is a subset of vimpeccable. I imitated the mapping feature only from it.
- Mappy - Wikipedia
- Mappy is a great game. (no related for this plugin ;)