Create snippets from existing textλ︎
helm-yas-create-snippet-on-region is an effective way to create snippets from existing text.
Select a code block that you often create and using the yasnippets tools to create your own generic template
- v for visual select and highlight the text for the snippet. Or use Space v and grow the selected region with v
- Space Space
helm-yas-create-snippet-on-regioncreates a new snippet
- Enter the name you wish to refer to this snippet
- Select the major mode you want to add the snippet too (eg. clojure, markdown, html)
- Edit the text and delete any text that is not required
- Add tab points in the snippet if relevant
$1initial cursor position,
$2next cursor position on tab,
$0end cursor position.
- Ctrl+c Ctrl+t calls
yas-tryout-snippetto test the snippet has the right behaviour
- Ctrl+c Ctrl+c calls
yas-load-snippet-buffer-and-closeto load the snippet into the specified major mode and closes the snippet buffer
Edit an existing snippetλ︎
yas/visit-snippet-file displays a helm popup listing snippets.
Enter a pattern to narrow the list or Ctrl j and Ctrl k to navigate the snippets. Enter to select the snippet.
Edit the snippet and Space f s to save file
C-c C-c calls the function
yas-load-snippet-buffer-and-close which loads the snippet into Spacemacs and closes the buffer.
C-c C-t calls
yas-tryout-snippet to test the snippet and check the placement of your tab stops.