Skip to content

Commit

Permalink
docs(snippets): add note about not using <C-n>/<C-p> keys in mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Dec 26, 2024
1 parent 13b2331 commit 84ade0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions doc/mini-snippets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ the duration of active snippet session(s) from |MiniSnippets.default_insert()|.
Used to jump to next/previous tabstop and stop active session respectively.
Use |MiniSnippets.session.jump()| and |MiniSnippets.session.stop()| for custom
Insert mode mappings.
Note: do not use `"<C-n>"` or `"<C-p>"` for any action as they conflict with
built-in completion: it forces them to mean "change focus to next/previous
completion item". This matters more frequently than when there is a tabstop
with choices due to how this module handles built-in completion during jumps.

# Expand ~

Expand Down
13 changes: 9 additions & 4 deletions lua/mini/snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ end
--- Used to jump to next/previous tabstop and stop active session respectively.
--- Use |MiniSnippets.session.jump()| and |MiniSnippets.session.stop()| for custom
--- Insert mode mappings.
--- Note: do not use `"<C-n>"` or `"<C-p>"` for any action as they conflict with
--- built-in completion: it forces them to mean "change focus to next/previous
--- completion item". This matters more frequently than when there is a tabstop
--- with choices due to how this module handles built-in completion during jumps.
---
--- # Expand ~
---
Expand Down Expand Up @@ -2572,10 +2576,11 @@ end

H.hide_completion = function()
-- NOTE: `complete()` instead of emulating <C-y> has immediate effect
-- (without the need to `vim.schedule()`). The downside is that `fn.mode(1)`
-- returns 'ic' (i.e. not "i" for clean Insert mode). Appending
-- ` | call feedkeys("\\<C-y>", "n")` removes that, but still would require
-- workarounds to work in edge cases.
-- (without the need to `vim.schedule()`). The downsides are that `fn.mode(1)`
-- returns 'ic' (i.e. not "i" for clean Insert mode) and <C-n>/<C-p> act as if
-- there is completion active (thus not allowing them as custom mappings).
-- Appending ` | call feedkeys("\\<C-y>", "n")` removes that, but still would
-- require workarounds to work in edge cases.
if vim.fn.mode() == 'i' then vim.cmd('noautocmd call complete(col("."), [])') end
end

Expand Down

0 comments on commit 84ade0b

Please sign in to comment.