3

When you insert a snippet from Yasnippet, you have this, for example

# --------------------------------------------------------------
# $1 (`(insert-date)`)
# --------------------------------------------------------------
$2

Then you press tab, to switch from the place $1 to the place $2.

If you are not in a snippet, the tab key works normal.

I figured out the function that's get called when you press Tab into snippet, is yas-next-field. I would like to bind the function to another key instead Tab.

But only when it's inside a snippet, not affecting the normal working of another key outside snippet, like Tab already is.

But I couldn't find any refefence on internet about keymapping for only inside yasnippet, not as normal key.

Thanks in advance for the suggestion, it's really appreciated.

1 Answer 1

5

Customize yas-keymap for that.

(eval-after-load 'yasnippet
  '(progn
     (define-key yas-keymap (kbd "TAB") nil)
     (define-key yas-keymap (kbd "C-o") 'yas-next-field-or-maybe-expand)))
3
  • Thanks Wasamasa! That worked it right. But how could you figure that out, if I might ask? I found nothing about that on Yasnippet documentation.
    – ReneFroger
    Apr 20, 2015 at 6:55
  • I've read the source code and found three keymaps, one of which was using yas-next-field-or-maybe-expand.
    – wasamasa
    Apr 20, 2015 at 8:14
  • Reading the source code, that could be an option too... would be a hell of job for me personally. I still have some difficulties to understand Elisp code. I'm planning to learn Elisp at the end of April. Thanks Wasama, it's really appreciated.
    – ReneFroger
    Apr 20, 2015 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.