-
Notifications
You must be signed in to change notification settings - Fork 20
Mappings
dcampos edited this page Jun 30, 2025
·
7 revisions
Some examples of mappings in Lua.
A better approach, instead using Snippy's mapping setup options, is to map to Lua anonymous functions that defer loading Snippy until the mapping is actually used:
local map = vim.keymap.set
map({ 'i', 's' }, '<tab>', function()
return require('snippy').can_expand_or_advance() and '<plug>(snippy-expand-or-advance)' or '<tab>'
end, { expr = true })
map({ 'i', 's' }, '<s-tab>', function()
return require('snippy').can_jump(-1) and '<plug>(snippy-previous)' or '<s-tab>'
end, { expr = true })
map('x', '<Tab>', '<plug>(snippy-cut-text)')
map('n', 'g<Tab>', '<plug>(snippy-cut-text)')This is also suitable for use with plugin managers like lazy.nvim.
See the nvim-cmp wiki for an example of how to do it with cmp.
Mappings created with :vmap or mode v apply to both Visual and Select modes, which can potentially interfere with snippet expansion in Select mode. Consider using mode x for Visual-only mappings and mode s for Select-only mappings.
In Select mode, non-printable characters behave the same as in Visual mode. To make them delete the selection and enter Insert mode, you need to map them accordingly. Here is an example:
-- Make C-h, Delete and Backspace delete selection and enter Insert mode
vim.keymap.set('s', '<BS>', '<c-g>"_c')
vim.keymap.set('s', '<C-h>', '<c-g>"_c')
vim.keymap.set('s', '<Delete>', '<c-g>"_c')