This isn't an official plugin reimplementation. I am not in any way affiliated with UltiSnips developer(s).
I needed this functionality in Vis, and UltiSnips seemed powerful and mature enough, and had plenty of templates available.
- Install plugin (clone or use vis-plug)
- (Optionally) Clone snippets from vim-snippets
- Configure plugin paths and mappings inside your
visrc.lua
- Use
<C-x><C-j>
to execute
Clone vis-ultisnips
into your .config/vis/plugins
directory
As per vis-plug
instructions, add to your visrc.lua
:
-- configure plugins in an array of tables with git urls and options
local plugins = {
...
{ url = '[email protected]:machinedgod/vis-ultisnips', alias = 'snips' },
...
}
-- require and optionally install plugins on init
visplug.init(plugins, true)
We assign alias snips
to use in subsequent configuration.
If you don't already have snippets, get them. Of course, you can just create your own as well.
In your visrc.lua
:
snips.snipmate = '<path-to-SnipMate-snippets>'
snips.ultisnips = '<path-to-SnipMate-UltiSnips>'
Trailing slash is necessary!
If you're using vis-plug
, configuration must come after you execute
visplug.init(...)
as shown in Installation:
-- access plugins via alias
visplug.plugins.snips.snipmate = '/home/john/.config/vis/vim-snippets/snippets/'
visplug.plugins.snips.ultisnips = '/home/john/.config/vis/vim-snippets/UltiSnips/'
Setup any lexer syntax file to snippet file mapping using two tables,
one for each snippet format. The key is the vis lexer (the thing you
type when you set syntax with :set syntax syntaxfile
), while the value
is the string representing the filename of the snippetfile, without
extension.
The default mapping includes cpp.lua
lexer to SnipMate's c.snippets
file as below.
If you report it as an issue (or even more lovely, as a pull request),
I'll add it to default maps, but to quickly get it to work without
messing with the init.lua
file, add the mappings in your visrc.lua
(purescript is just an example!):
snips.syntaxfilemaps =
{ snipmate = { cpp = "c"
, purescript = "pure"
}
, ultisnips = { purescript = "pure"
}
}
In insert mode, hit <C-x><C-j>
to show vis-menu
with all snippets
found for the currently set syntax - it literally looks for a file in
your path called <syntax>.snippet
.
You can also pre-type the snippet tabtrigger that you're looking for, for example:
newt<C-x><C-j>
When snippet is expanded, all of its tags will be added to the selection
jumplist with first tag selection(s) active. You can use Vis motions
g<
and g>
to navigate between them.
You can:
- get a list of snippets per syntax
- insert the snippet
- navigate around its anchor points
What is known to not work and is unlikely to work until someone else fixes it (ie. I don't care much about it right now)
- python interpolations, date interpolations, etc etc etc
- nested tags (correctly parsed, but not correctly inserted)
- options
-
Parsing of more complex snippets. Lpeg grammar for this is quite complex (I'm looking at you, nested tags feature)
-
vis-menu
for one or the other reason corrupts my terminal when invoked. This might be plugin doing something its not supposed to - but I don't know what. If you do, please PR. Mind you, dmenu has no such problems. -
who knows??? This was supposed to be few hours project max, ended up being a rabbit hole!
All of this, because muscle memory from vim made me remember I can't
just insert {-# LANGUAGE ...#-}
pragma via template.
And I didn't like that.
So I spent upwards of 15h writing this plugin.
Go figure.