Skip to content

Commit

Permalink
show lua-mappings in readme.
Browse files Browse the repository at this point in the history
Show both the lua-api, and a different set of mappings (since
overloading tab has some annoying side-effects).
  • Loading branch information
L3MON4D3 committed Jul 10, 2023
1 parent a658ae2 commit 572f202
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Neovim >= 0.5 (extmarks)
Consider watching the repos releases so you're notified when a new version becomes available.

## Keymaps
In vimscript, with `<Tab>` for jumping forward/expanding a snippet, `<Shift-Tab>` for
jumping backward, and `<Ctrl-E>` for changing the current choice when in a
choiceNode...
```vim
" press <Tab> to expand or jump in a snippet. These can also be mapped separately
" via <Plug>luasnip-expand-snippet and <Plug>luasnip-jump-next.
Expand All @@ -75,6 +78,23 @@ snoremap <silent> <S-Tab> <cmd>lua require('luasnip').jump(-1)<Cr>
imap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
smap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
```

... or in lua, with a different set of keys: `<Ctrl-K>` for expanding, `<Ctrl-L>`
for jumping forward, `<Ctrl-J>` for jumping backward, and `<Ctrl-E>` for
changing the active choice.

```lua
vim.keymap.set({"i"}, "<C-K>", function() ls.expand() end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-L>", function() ls.jump( 1) end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-J>", function() ls.jump(-1) end, {silent = true})

vim.keymap.set({"i", "s"}, "<C-E>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end, {silent = true})
```

`nvim-cmp`'s wiki also contains [an example](https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip) for
setting up a super-tab-like mapping.

Expand Down

0 comments on commit 572f202

Please sign in to comment.