Luasnip and Treesitter for Smarter Snippets

TL;DR A context-aware snippet for Go error handling code, returning the right types, with the default values. Demo Snippet EDIT(2024-02-23): TJ DeVries made a video explaining an improved version of this snippet. You may still find the discussion on Go errors in this post interesting. Introduction Golang’s error handling is notoriously verbose. It was also the top pain point in the Go Developer Survey Q2 2022. Numerous proposals to simplify error handling have been written, but at the time of writing, none have been accepted. ...

August 30, 2023 · 10 min · Clément Joly

Generating Snippets with LuaSnip in Neovim

TL;DR When you have many variations of the same snippet, one option is to generate those with Lua code. The complete example is at the end. I’ve recently moved to LuaSnip as my snippets plugin for Neovim. When I first started, I sticked to the simplest features of LuaSnip, in particular the SnipMate-like syntax for snippets. But I have now started to explore the more distinctive features of LuaSnip, like Lua-defined snippets. It turns out that generating snippets with code can save tedious repetition. ...

July 31, 2022 · 4 min · Clément Joly

From UltiSnips to LuaSnip

TL;DR LuaSnip is fast and doesn’t have to be complicated. Give it a try! Even if that article shows how LuaSnip shines, I have great respect for the work that has gone into UltiSnips. It is still a reliable, reasonably fast plugin given the constraint it operates in (in particular, Vim compatibility requires a fair amount of Vimscript). I’ve written this article shortly after trying LuaSnip and I’m still very much evaluating it. ...

May 15, 2022 · 7 min · Clément Joly