-
Notifications
You must be signed in to change notification settings - Fork 18
Mappings
dcampos edited this page Jan 17, 2023
·
5 revisions
Some example mappings in Lua.
Using vim.keymap.set()
(Neovim 0.7+) allows creating mappings in a concise way, especially if you don't need to call setup()
for a different reason. The snippy.mapping.*
functions return a function themselves and allow passing a fallback key.
local mappings = require('snippy.mapping')
vim.keymap.set('i', '<Tab>', mappings.expand_or_advance('<Tab>'))
vim.keymap.set('s', '<Tab>', mappings.next('<Tab>'))
vim.keymap.set({ 'i', 's' }, '<S-Tab>', mappings.previous('<S-Tab>'))
vim.keymap.set('x', '<Tab>', mappings.cut_text, { remap = true })
vim.keymap.set('n', 'g<Tab>', mappings.cut_text, { remap = true })
Another approach, not using the snippy.mapping.*
functions, is to use the following:
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)')
These are 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.