Ever had to send the same email again and again? This is very common in office environments and we have a way to avoid this hassle (apart from just copy and paste). While in coding we rely on snippets like YASnippet in emacs or UltiSnips/LuaSnip for vim/neovim to save time and write code easily and quick, I haven't seen an alternative for system global snippets.

In this context, a snippet is a short keyword that expands to a complete text or function. For example, typing src in org-mode in emacs using YASnippet, will expand to a source block:

1
2
3
4
5
src -> TAB ->

#+begin_src

#+end_src

See, in the previous example I included/pressed TAB after the keyword, in YASnippet it is necessary to press it in order to expand the snippet (there is a pull request to auto-expand), but in others snippet tools it will auto-expand, this is the case of espanso.

espanso

Espanso is a system global snippet tool. It works in Linux, macOS and Windows. It works exactly as YASnippet or UltiSnips, you type a keyword, espanso detects it and expands it to a text/match you have defined.

Espanso, auto-expands the keyword, so the recommendation is to add a colon : at the beginning of the keyword to avoid problems. Say you have the following match for :email:

1
2
3
4
5
6
7
matches:
  - trigger: ":email"
    replace: |
      Dear $|$,
      Hope this email finds you well,

      Best regards.

Now everytime, you type :email, it will auto-expand to thes difined text and move the cursor to the position $|$.

Final thoughts

  • This was a brief introduction to espanso. It can handle more than simple snippets, like: forms, regex, shell commands. So check the official documentation for more examples.
  • I actually came to know about espanso from KMK's string substitution module. It is like having espanso installed in your keyboard and it will work in any computer/device you connect the keyboard to.
  • I normally use YASnippet when codding and blogging. I have several python scripts to automate sending email reports, but for other kind of emails, like requesting information, I started using espanso.
If you found this content useful, please support me:
BTC: 1E2YjL6ysiPxRF4AEdXChpzpesRuyzgE1y