Git Product home page Git Product logo

zsh-snippets's Introduction

zsh-snippets

Persistent zsh-snippets based on 1ambda/zsh-snippets

  • add, udpate, delete, list snippets
  • supports auto-completion

Install: zplug

Setup aliases and widgets while binding keys with them

  • CTRL-[SPACE] expands the specified snippet
  • CTRL-Z lists existing snippets
# in .zshrc
zplug "verboze/zsh-snippets"
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)

Usage

All commands and snippets are auto-completed by stroking tab key

# add a `gj` snippet
# tip: you could add these into your zshrc if you wish
$ zsp --add gj "| grep java | grep -v grep"

# list snippets
# or type binded key `^Z` (CTRL+Z)
$ zsp --list

# expand a snippet
# '!' means your current cursor in terminal, type your binded key `^ ` (CTRL+[SPACE])
# note: spaces after the keyword will be removed, so the two below are equivalent
$ ps -ef gj!
$ ps -ef gj  !

# will be expanded into
$ ps -ef | grep java | grep -v grep

# jump to a "tabstop" in the snippet (tabstops are defined with `${\w+}`)
# NOTE: ! is the current cursor position in the lines below
$ zsp --add echotest 'echo "${msg1}" "${msg2}"'!
$ echotest! # 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

Development

Load local zsh-snippets

# in .zshrc
zplug "$SOMEWHERE/zsh-snippets", from:local, use:'snippets.plugin.zsh'

License

MIT

zsh-snippets's People

Contributors

verboze avatar 1ambda avatar

Stargazers

Ryan Cabanas avatar Philipp Dörfler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.