I'm trying out HyperSnips to make it easier to type
It turned out to be pretty hard to work directly with the vanilla .hsnips files, especially when I have to a bunch of JavaScript to implement something complex like auto-fraction (inspired by Latex Suite for Obsidian).
That's why I'm using snipbuild, a build tool that I wrote to solve this problem.
- Global block JavaScript is developed with TypeScript and unit-tested with Vitest. It makes maintainance far easier.
- Each
src/globals/[LANGUAGE].tsexports what will be included in the global block of the corresponding snippet file.
- Each
- The snippet blocks for each language is located at
src/snippets/[LANGUAGE].hsnips. It is in the exact same format as normal.hsnipsfiles except:- It does not have the
global ... endglobalblock at the top. - It allows you to include common snippets shared by several (but not necessarily all) languages using
#include "...".
- It does not have the
- When running
pnpm build, Rolldown generates the global JavaScript fromsrc/globals/[LANGUAGE.ts], and the output is concatenated with the snippet blocks fromsrc/snippets/[LANGUAGE].hsnips.
pnpm ito install dependenciespnpm buildto generate snippet files under thedist/directory- Install the generated snippet files. On macOS, you can just run
maketo do it. - Make sure you execute the
HyperSnips: Reload Snippetscommand after updating the snippet files.
Once you install the snippets using symbolic links (as shown above), all you have to do after making edit to the source code is pnpm bulid & HyperSnips: Reload Snippets.
This repo is still very young and many useful snippets are yet to be added. To customize snippets by yourself, edit the following files:
- Global blocks:
src/globals/[LANGUAGE].hsnips - Snippet blocks:
src/globals/[LANGUAGE].hsnips
By default, VSCode accepts a suggestion when <Tab> is pressed. This causes conflicts with snippets with tab stops.
To fix it, run Preferences: Open Keyboard Shortcuts (JSON) command, and add the following to keybindings.json:
{
"key": "tab",
"command": "-acceptSelectedSuggestion"
}
Ignore this section if you're not a vscodevim user!
By default, you have to press <Esc> twice to go back to Normal mode after expanding a snippet. This is annoying!
To fix this, install multi-command and add the following to keybindings.json:
{
"key": "escape",
"command": "extension.multiCommand.execute",
"args": {
"sequence": ["leaveSnippet", "extension.vim_escape"]
},
"when": "editorTextFocus && vim.active && inSnippetMode"
}
- Gilles Castel's amazing blog post and UtilSnip snippets
- artisticat's Latex Suite plugin for Obsidian
- Seriously, it proved pretty difficult to recreate in VSCode/Cursor what LaTeX Suite makes possible in Obsidian, which made me realize what a well-written piece of software it is. Crazy work.
- Especially inspired by her implementation of auto-fraction