Persistent zsh-snippets based on verboze/zsh-snippets
- add, update, delete, list snippets
- supports auto-completion
👆 Note: This GIF is slightly out of date, it's from the OG repository.
git clone to some directory
# in .zshrc source /where/you/cloned/the/repository/to/snippets.plugin.zsh alias zsp="zsh_snippets" bindkey '^ ' zsh-snippets-widget-expand # Ctrl+SPACE (expand) bindkey '^Z' zsh-snippets-widget-list # Ctrl+Z (list) bindkey '^N' jump_to_tabstop_in_snippet # Ctrl+N (jump to tabstop)
exec zsh # to "reload" your zsh
# add a `gj` snippet $ zsp add gj "| grep java | grep -v grep" # list snippets # or type binded key `^Z` (Ctrl+Z) $ zsp list # expand a snippet # type your binded key `^ ` (Ctrl+Space) # note: spaces after the keyword will be removed, so the two below are equivalent $ ps -ef gj<Ctrl+Space> $ ps -ef gj <Ctrl+Space> # will be expanded into $ ps -ef | grep java | grep -v grep # jump to a "tabstop" in the snippet (tabstops are defined with `${\w+}`) $ zsp add echotest 'echo "${msg1}" "${msg2}"'! $ echotest<Ctrl+Space> # expand the snippet to... $ echo "${msg1}" "${msg2}"! # now hit Ctrl+N. line becomes: $ echo "!" "${msg2}" # the cursor is now positioned where the tabstop was, with the tabstop ${msg1} deleted $ echo "text that I typed!" "${msg2}" # type some text, and hit Ctrl+N again. Line becomes: $ echo "text that I typed" "!" # NOTE: when jumping to tabstops, the cursor can be anywhere on the line. We will always jump to the leftmost tabstop # delete a snippet zsp delete gj # Quoting zsp add red "ruby -e 'while gets(); \${code}; puts \$_ end'"
MIT