Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show tab-based mapping in the README #16

Open
Julian opened this issue Nov 23, 2020 · 1 comment
Open

Show tab-based mapping in the README #16

Julian opened this issue Nov 23, 2020 · 1 comment

Comments

@Julian
Copy link

Julian commented Nov 23, 2020

Hi! (Thanks for making this!)

Other snippets plugins often show a quick snippet (ugh no pun intended) for how to "smart-map" <Tab> to either expand, jump to next slot, or insert a tab key (or ideally trigger completion).

Usually involving e.g. coc#expandableOrJumpable() for coc-snippets, or similar for vsnip, etc.

I'm sure there's likely a way to do so with snippets.nvim -- may be nice to have it in the README.

(Happy to send a PR if/when I figure out how to do so by jumping into the source).

@Julian
Copy link
Author

Julian commented Nov 29, 2020

OK, I found snippets.lookup_snippet_at_cursor which meant I ended up with:

-- Expand a snippet if it exactly matches, otherwise complete.
function tab()
  local _, expanded = snippets.lookup_snippet_at_cursor()
  if expanded ~= nil then
    snippets.expand_at_cursor()
    return
  end
  completion.smart_tab()
end

which I'm sure is still slightly inefficient because it expands the snippet twice but does seem to do what I want personally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant