Skip to content

Mappings

dcampos edited this page Aug 12, 2024 · 5 revisions

Some examples of mappings in Lua.

Lazy mappings

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.

Super-tab like mappings

See the nvim-cmp wiki for an example of how to do it with cmp.

Clone this wiki locally