dcampos / nvim-snippy Goto Github PK
View Code? Open in Web Editor NEWSnippet plugin for Neovim written in Lua
License: MIT License
Snippet plugin for Neovim written in Lua
License: MIT License
It seems that currently, only the first occurrence of specified tabstop will be expanded, even if it's a regex transformed tabstop of a latter (real) one.
snippet readint
scanf("%d${1/[^,]*,[^,]*/%d/g}", $1);
Here I'm trying to automatically generate scanf()
format string for reading multiple int
s in C/C++ (contains of multiple %d
s) of arguments $1
. However, snippy only tries to expand the first occurrence of $1
, and it broke this snippet. Swapping these two occurrence of tabstop $1
works fine as expected.
I think it doesn't really make sense to expand transformed tabstop in the first place, since its just a substitute of a real tabstop with user input.
EDIT 1: I could confirm this snippet works as expected with VSCode.
EDIT 2: $1
set to &a, &b, &c
will expand the snippet to scanf("%d%d%d", &a, &b, &c);
Hi!
First of, thank you again for this great plugin. I really enjoy using it!
I noticed <C-i>
was not working in my neovim configuration and when I started to investigate (using :map <C-i>
) I noticed that I had it mapped to snippy-cut-text
. But I didn't do that. verbose
tells me the mapping is comming from my lua config. The relevant sections are:
local snippy = require('snippy')
snippy.setup({
mappings = {
is = {
["<Tab>"] = "expand_or_advance",
["<S-Tab>"] = "previous",
},
nx = {
["<Tab>"] = "cut_text",
},
},
})
and if it matters, cmp-snippy is also installed
local cmp = require('cmp')
cmp.setup({
sources = cmp.config.sources({
{ name = 'snippy' },
}),
snippet = {
expand = function(args)
require('snippy').expand_snippet(args.body)
end,
}
})
So now I am wondering why <C-i>
is being mapped to snippy-cut-text
.
I've searched my whole nvim config directory for the strings that would create this mapping in VimL and Lua and could not find anything, so I'm wondering if this is perhaps a problem with snippy or cmp-snippy?
Thank you in advance!
Example case: I have a snippet for C++ for
loop, which expands to
for (int i = 0; i < counter; i++)
{
}
But when I <Tab>
to i
(with all three of them to be edited in the selection mode), and want to repalce it with j
, my cursor moves down instead, extending the selection. The same happens with k
, but this time cursor goes up one line. Other letters seem to work fine, i.e. I have no problem with replacing i
with, e.g., s
. I tried the same with almost all of other plugins disabled (including nvim-cmp
), still behavior is the same. Franky, I am surprised to see that pressing letter keys in the selection
mode works like in the visual
mode (not replacing the selection).
It looks like there is some issue when trying to expand a snippet from inside another.
First snippet:
snippet s1
local ${1:var} = ${0:value}
Second snippet:
snippet s2
require(${1:modname})
The modname
placeholder gets selected.
The placeholder is skipped and the cursor jumps to the end of the line.
No response
Is there a way to switch to normal mode and not stay in insert mode after ending a snippet completion ? It would like to be able to do that for specific snippets.
I use a custom completion mechanism written in Lua (see here). This completion mechanism supports inserting snippets using Snippy and LSP snippets. One feature is that if there's a single entry, it's expanded immediately instead of requiring you to confirm it.
Today I noticed this seems to break the tab stops in snippets. For example, I have this snippet:
snippet context "Insert a context block"
context '${1:description}' do
${0}
end
When I type context
then trigger snippy.can_expand()
through an insert mapping, all is fine and the tab stops work properly. However, when I trigger the expansion using my completion mechanism (by pressing Tab in my case), it does expand the snippet, but I can't jump to any placeholders.
Running git bisect
revealed this started happening with commit 656a232. Commits before that one work just fine.
Annoyingly I haven't been able to narrow this down to something simple. For example, if I do snippy.expand_snippet(snippy.snippets.ruby.context)
in the completion code, it also doesn't work. Weirdly enough, it does work when I use this mapping:
imap <C-t> <cmd>lua require('snippy').expand(vim.inspect(require('snippy').snippets.ruby.context))<cr>
Hi!
Thanks for the implementation of the auto-trigger feature! It works very well but the only issue so far has been the delay it takes for it to start. For example, when launching a latex file (having defined tex.snippets
), when using snippets using auto-trigger, it doesn't work at all for a couple of seconds. However, after this delay it works very well. The issue is the finite time it takes from launching a file and expanding the snippet.
I know that the help.txt specifies a dip in performance when using auto-trigger. Is it an inherent issue with lua or can it be fixed in the plugin in the future?
Hi!
I was wondering if like UltiSnips, nvim-snippy has options for triggers. For example, in UltiSnips
snippet ss1 "Subsection*" A
\subsection*{$1}
$0
endsnippet
would mean that typing ss1
would instantly place the template without pressing <Tab>
(A
in the first line means automatic). Is this sort of thing possible with nvim-snippy?
With miniyank
, I have p
mapped to <Plug>(miniyank-autoput)
:
:map p
p <Plug>(miniyank-autoput)
Then, for example when completing this snippet:
snippet fn "Function definition"
fn ${1:function_name}(${2})${3} {
${0}
}
and pressing p
to type the first character of function_name
, neovim appears to run the miniyank-autoput
command instead of inserting the p
character.
See this demo where I first yank foobar
and then complete the snippet with fn<tab>
, and insert p
as the first character of the function name, and then press p
repeatedly.
Every other character works normally, and even p
works if I type something else as the first character of the function.
If I unmap p
, the problem goes away.
Any ideas? Thank you!
See description.
See description.
See description.
No response
I have a really niche use case here. Both Vim and Neovim have a handy feature that allows a file to be recognized as multiple filetypes, then various scripts and autogroup actions can be ran for each of the filetypes that applies. As an example I'm using the Vimwiki plugin to edit markdown files, some types of markdown can also be considered a pandoc file as well. In neovim if I open a markdown file and issue the command :set filetype
it shows the current filetype as vimwiki.markdown.pandoc
as expected. However, this plugin doesn't recognize this as a list of filetypes. Instead, as far as I can tell, it recognizes a single filetype vimwiki.markdown.pandoc
and doesn't load until I issue the command set filetype=markdown
. At any rate, thanks again for this rad plugin!
First of all, thanks! Great plugin!
Would it be possible to enable the plugin to support mixed vim functions and static texts in the placeholder choices? Something like:
snippet today
${1|`strftime('%c')`,today|}
The replacement part of regex transformations doesn't seem to work when empty. For example:
local $1 = ${1/_//g}
Entering my_snake_case_variable
should result in mysnakecasevariable
. Currently the transform isn't even being parsed correctly; the raw text is inserted when the snippet is expanded:
local var_name = ${1/_//g}
Sometimes some error messages like col vlaue out of range
pop up.
run nvim -u vimrc.vim test.py
Then we go ahead and press the tab
key to make the cursor jump to the comment.
Type something random and when we type the second letter, an error message will pop up
test.py
def
vimrc.vim
if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'dcampos/nvim-snippy'
Plug 'honza/vim-snippets'
call plug#end()
PlugInstall | quit
imap <expr> <Tab> snippy#can_expand_or_advance() ? '<Plug>(snippy-expand-or-advance)' : '<Tab>'
imap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
smap <expr> <Tab> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<Tab>'
smap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
xmap <Tab> <Plug>(snippy-cut-text)
lua << EOF
require('snippy').setup({
hl_group = 'Search',
})
EOF
nvim version: NVIM v0.7.0-dev+913-ge07a4b97f6
I can provide any other information if needed
Snippet:
snippet testing "This is a test"
Placeholder: ${1:}
When expanding this, the output is:
Placeholder: }
Placeholders like this are used by e.g. gopls. I'm not sure what other snippet managers do, with perhaps simply showing a space might suffice.
I was looking at the code of snippy in search of the smallest/most sensible snippet plugin there is (written in Lua). Snippy looks interesting because:
While looking at the code I ran into the following lines:
Line 322 in c441127
Line 411 in c441127
The function called (
nvim-snippy/lua/snippy/buf.lua
Line 152 in c441127
Now I don't know exactly why snippy needs this, but the combination of defer_fn
and what seems to be a random delay strikes me as a bit odd. In particular, I think it's possible for the user to change text (for example) before the deferred function is called. Whatever Snippy needs these event hooks for may then not work.
Is the use of defer_fn
really necessary here? If so, what are they used for? Thanks! ๐
An error appear while delete a line which just snippy completed.
E5108: Error executing lua ...m/site/pack/packer/start/nvim-snippy/lua/snippy/stop.lua:32: attempt to index a nil value
Example:
snippet if
if $1 then
$2
end
snippet two
$1
$2
Type:
if<tab>something<tab>two<tab>1<tab>2
Expands to:
if something then
1
2
end
The second tabstop isn't indented.
Is there any plans for this project to support vscode-style snippets? While I agree that snipmate syntax is much friendly when it comes to writing snippets, I personally found that existing collection, rafamadriz/friendly-snippets, is better than honza/vim-snippets. The former, unfortunately, maintains snippets using vscode syntax.
I think the doc man be a bit clearer on some topics. For example, snippet_dirs is the directory containing the snippets folder. This one caused me a lot of headache as I thought snippet files had to be in snippet_dirs. Also you should mention that snippet definitions have to indented using tab. Thanks for the plugin btw. It's simple and it works like a charm.
set encoding=utf-8
"dein Scripts-----------------------------
if &compatible
set nocompatible " Be iMproved
endif
set runtimepath+=~/.cache/nvim/dein/repos/github.com/Shougo/dein.vim
call dein#begin($HOME . '/.cache/nvim/dein')
call dein#add($HOME . '/.cache/nvim/dein')
call dein#add('hrsh7th/nvim-cmp')
call dein#add('hrsh7th/cmp-buffer')
call dein#add('dcampos/cmp-snippy')
call dein#add('dcampos/nvim-snippy')
call dein#add('honza/vim-snippets')
call dein#end()
call dein#call_hook('source')
call dein#call_hook('post_source')
if has('vim_starting')
let g:dein#auto_recache = 1
endif
" Required:
filetype plugin indent on
syntax enable
set background=dark
imap <expr> <Tab> snippy#can_expand_or_advance() ? '<Plug>(snippy-expand-or-next)' : '<Tab>'
smap <expr> <Tab> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<Tab>'
imap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<Tab>'
smap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<Tab>'
lua << EOF
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
require 'snippy'.expand_snippet(args.body)
end,
},
sources = {
{ name = "buffer" },
{ name = 'snippy' }
},
mapping = {
["<S-TAB>"] = cmp.mapping.select_prev_item(),
["<TAB>"] = cmp.mapping.select_next_item(),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm()
},
})
EOF
nvim -u minimal.vim a.c
time
, press tab
, cr
.Originally posted by raine October 11, 2022
If you use snippets such as these with snippy, you'll notice that the empty lines after the snippets (before the next snippet) are expanded as well.
Am I missing something obvious or is this a bug? A simple fix is to manually remove every blank line but the README claims snipMate compatibility so I was wondering about this.
^ Notice the extra empty line added when the snippet expands.
Thanks!
use {'dcampos/snippy'}
Packer shows following error.
โ Failed to install dcampos/snippy
Errors:
Cloning into '/home/s1n7ax/.local/share/nvim/site/pack/packer/start/snippy'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
However, cmp-snippy
installs without any issue.
First of all thank you for this library. I've used most of the available snippet plugins for vim / nvim and this is my favorite.
My only problem is that there are certain snippet sources that interfere with function definitions for several languages. They often pop up when I try to use a closing parens )
or brace }
. It's really driving me crazy. The additional typing that I need to do to avoid these unwanted completions pretty much negates the benifit of having the snippets that I actually use.
I used the same snippet source (honza/vim-snippets
) with UltiSnips and never had this issue in any language.
Here's my config:
use {
'dcampos/nvim-snippy',
requires = {
{ 'honza/vim-snippets' },
{ 'dcampos/cmp-snippy' }
},
}
Any idea where these snippets are coming from and how I can disable them?
Hello,
when I complete a snippet from an LSP suggestion the tab stops do not work, I cannot jump between them. Instead the original meaning of the keys is applied. Regular snippets I have defined myself in snippets/*.snippets
files work as expected. Here are my settings:
-- plugin/snippets.lua
local snippy = require 'snippy'
snippy.setup {
}
" plugin/snippets.vim
imap <expr> <Tab> snippy#can_expand() ? '<Plug>(snippy-expand)' : '<C-]>'
imap <expr> <C-n> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<C-j>'
imap <expr> <C-p> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<C-k>'
smap <expr> <C-n> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<C-j>'
smap <expr> <C-p> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<C-k>'
I use a patched completion.nvim as the completion plugin. Obviously I am not getting completion candidates for my own snippets, but I do get suggestions for snippets from LSP and I can accept them, which fills in the snippet contents properly.
I had been using UltiSnips before and it worked there. I am looking for a simpler replacement that does not have external dependencies, and so far snippy looks like the perfect fit if I can make LSP snippets work.
function
)I need to be able to jump between the tab stops of the snippet, i.e. function name, parameters and body in the case of function
.
I cannot jump, snippy#can_jump
is always returning false. Is there some extra step needed to be done by the completion plugin?
I also noticed that there are no placeholders inserted, but I am not sure if there are supposed to be any.
Currently the <Plug>
mapping is expand-or-next
and the actual Lua function is expand_or_advance
. I'm thinking about deprecating any 'expand-or-next' reference in favor of 'expand-or-advance', specially because there already is a can_expand_or_advance
function too, which sounds better than can_expand_or_next
.
If you have a snippet with mirrored tabstops, and you expand a snippet in the first one, the expanded snippet is immediately mirrored to the other tabstops, except that you are in a new nested snippet, and updating this won't update the mirrored tabstops.
Sample lua snippets used in clip:
snippet ifr
if $1 then
$2
$2
$3
end
snippet if
if $1 then
$2
end
Complete ifr
snippet up to $3, expanding if
at $2, then go back to $1, change again $2, again back to $1.
Mirrored nested snippets are actually mirrored. Also a delayed mirroring would be ok.
Snippy can actually update the mirrored tabstops, but only if the parent of the newly expanded snippet gets reselected. If you just exit the snippet normally, they aren't updated.
This patch (sort of) fixes it for me, but tabstops are updated on snippet exit, I couldn't do it in real time.
diff --git a/lua/snippy.lua b/lua/snippy.lua
index 0b07639..adc0e3c 100644
--- a/lua/snippy.lua
+++ b/lua/snippy.lua
@@ -79,34 +79,6 @@ local function present_choices(stop, startpos)
end, shared.config.choice_delay)
end
-local function mirror_stop(number)
- local stops = buf.stops
- if number < 1 or number > #stops then
- return
- end
- local cur_stop = stops[number]
- local startpos, _ = cur_stop:get_range()
- if startpos and startpos[1] + 1 > vim.fn.line('$') then
- buf.clear_state()
- return
- end
- local text = cur_stop:get_text()
- if cur_stop.prev_text == text then
- return
- end
- cur_stop.prev_text = text
- for i, stop in ipairs(stops) do
- if i > number and stop.id == cur_stop.id then
- stop:set_text(text)
- end
- end
- if cur_stop.spec.type == 'placeholder' then
- if text ~= cur_stop.placeholder then
- buf.clear_children(number)
- end
- end
-end
-
local function sort_stops(stops)
table.sort(stops, function(s1, s2)
if s1.id == 0 then
@@ -337,7 +309,7 @@ end
function M._mirror_stops()
if buf.current_stop ~= 0 then
- mirror_stop(buf.current_stop)
+ buf.mirror_stop(buf.current_stop)
end
end
@@ -365,7 +337,7 @@ function M._jump(stop)
return false
end
if buf.current_stop ~= 0 then
- mirror_stop(buf.current_stop)
+ buf.mirror_stop(buf.current_stop)
buf.deactivate_stop(buf.current_stop)
end
local should_finish = false
@@ -374,7 +346,7 @@ function M._jump(stop)
buf.clear_autocmds()
buf.activate_stop(stop)
- mirror_stop(stop)
+ buf.mirror_stop(stop)
local value = stops[stop]
local startpos, endpos = value:get_range()
diff --git a/lua/snippy/buf.lua b/lua/snippy/buf.lua
index 37fc3c0..0a0091d 100644
--- a/lua/snippy/buf.lua
+++ b/lua/snippy/buf.lua
@@ -11,13 +11,7 @@ M._state = {}
setmetatable(M, {
__index = function(self, key)
- if key == 'current_stop' then
- return self.state().current_stop
- elseif key == 'stops' then
- return self.state().stops
- else
- return rawget(self, key)
- end
+ return self.state()[key] or rawget(self, key)
end,
__newindex = function(self, key, value)
if key == 'current_stop' then
@@ -106,6 +100,7 @@ function M.state()
if not M._state[bufnr] then
M._state[bufnr] = {
stops = {},
+ mirrored = {},
current_stop = 0,
}
end
@@ -171,6 +166,35 @@ function M.update_state()
M.state().before = before
end
+function M.mirror_stop(number)
+ local stops = M.stops
+ if number < 1 or number > #stops then
+ return
+ end
+ local cur_stop = stops[number]
+ local startpos, _ = cur_stop:get_range()
+ if startpos and startpos[1] + 1 > vim.fn.line('$') then
+ M.clear_state()
+ return
+ end
+ local text = cur_stop:get_text()
+ if cur_stop.prev_text == text then
+ return
+ end
+ cur_stop.prev_text = text
+ for i, stop in ipairs(stops) do
+ if i > number and stop.id == cur_stop.id then
+ M.mirrored[number] = true
+ stop:set_text(text)
+ end
+ end
+ if cur_stop.spec.type == 'placeholder' then
+ if text ~= cur_stop.placeholder then
+ M.clear_children(number)
+ end
+ end
+end
+
function M.fix_current_stop()
local current_stop = M.stops[M.current_stop]
if not current_stop then
@@ -187,11 +211,15 @@ function M.fix_current_stop()
end
function M.clear_state()
+ for n, _ in pairs(M.mirrored) do
+ M.mirror_stop(n)
+ end
for _, stop in pairs(M.state().stops) do
api.nvim_buf_del_extmark(0, shared.namespace, stop.mark)
end
M.state().current_stop = 0
M.state().stops = {}
+ M.state().mirrored = {}
M.state().before = nil
M.clear_autocmds()
end
The undo history gets really messed up with repeated placeholders.
Example lua snippet:
snippet for
for ${1:k,v} in pairs(${2:table}) do
${3:code}
${3}
done
After editing the third placeholder, pressing u
repeatedly will only undo last edit.
Is there a way to provide priority for shippets?
What I'm looking for is some way to override one (or more) snippet with my own while using honza/vim-snippets
. In ultisnip
you could set priority in the fist line of snippet file like this:
priority -50
snippet blah "blah"
...
Then snippets in file with lower priority would be expanded in case of name conflict. Is there a way to achieve that in snippy?
Is it possible to expand a snippet inside another? E.g.:
snippet qtimestamp
`strftime("%Y-%m-%dT%H:%M:%S")`-03:00
snippet qheader
---
created: qtimestamp
modified: qtimestamp
type: Journal
---
On the example above, on the snippet "qheader", I would like to automatically expand the qtimestamp snippet on the "created" and "modified" fields.
Sometimes some error messages like bad argument #1 to 'unpack'
pop up with Codi.vim plugin. I'm not sure if this is a bug in nvim-snippy. If not, I will close this and open issue in Codi.vim plugin.
run nvim -u vimrc.vim test.py
run command :Codi
Then we type something random and error message will pop up.
test.py
def
vimrc.vim
if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'dcampos/nvim-snippy'
Plug 'honza/vim-snippets'
Plug 'metakirby5/codi.vim'
call plug#end()
PlugInstall | quit
imap <expr> <Tab> snippy#can_expand_or_advance() ? '<Plug>(snippy-expand-or-advance)' : '<Tab>'
imap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
smap <expr> <Tab> snippy#can_jump(1) ? '<Plug>(snippy-next)' : '<Tab>'
smap <expr> <S-Tab> snippy#can_jump(-1) ? '<Plug>(snippy-previous)' : '<S-Tab>'
xmap <Tab> <Plug>(snippy-cut-text)
lua << EOF
require('snippy').setup({
hl_group = 'Search',
})
EOF
nvim version: NVIM v0.7.0-dev+914-g7717f38d3f
I test vsnip and it works well with Codi.vim plugin.
I can provide any other information if needed
When a mirror tab stop is placed within a placeholder, its value is correctly mirrored correctly from the tab stop it refers to, but its parent placeholder's bounds aren't updated to include the mirrored value.
Steps to reproduce
local ${1:module} = ${2:$1}
.Expected behavior
Neovim should be in select mode and the word 'snippy' should become selected.
Actual behavior
Cursor is placed after the the mirrored word 'snippy' in insert mode.
Is snippy expected to fill empty tab stops with placeholder text? Using lua-language-server, most of the snippets already have placeholder text at the tab stops, but the function ()
snippet does not. Because of that I couldn't tell where the tab stops were:
snippy config:
return {
"dcampos/nvim-snippy",
config = function()
local loaded, snippy = pcall(require, "snippy")
if not loaded then return end
vim.api.nvim_create_autocmd("CompleteDone", {
group = vim.api.nvim_create_augroup("snippy", { clear = true }),
callback = function() snippy.complete_done() end,
})
snippy.setup({
mappings = {
is = {
["<tab>"] = "next",
["<s-tab>"] = "previous",
},
},
})
end,
}
local func
then trigger omnicomplete with <c-x><c-o>
function ()
snippet from the pop-up menu then hit <esc>
or <c-y>
The tab stops would have placeholder text to indicate where the tab stops are.
There's no placeholder text for tab stops.
No response
Right now snippets can only be indented with tabs, as per snipmate's approach. It could be a good idea to follow neosnippet here and allow indenting with spaces, as long as it is consistent.
Hi, it is nice to see a snippet plugin that does not require external dependencies.
I am wondering if there is a way to load additional snippets on demand. Ie if you have snippets available for certain filetype and based a condition you would like to add more snippets for current buffer only. A practical example for this feature can be test files. Where normal snippets can be used. But you could also have test specific snippets. I know that UltiSnips have a command UltiSnipsAddFiletypes
that allows to add additional snippets from a different filetype. Is something similar to this available or could be implemented with snippy?
Thanks
Snippet file snipptes/tex.snippets
:
priority 100
snippet ...
...
Error detected while processing FileType Autocommands for "*":
E5108: Error executing lua .../packer/start/nvim-snippy/lua/snippy/reader/snipmate.lua:110: Invalid priority in file /home/user/.config/nvim/after/snippets/tex.snippets, at line 1: 100
stack traceback:
[C]: in function 'error'
.../packer/start/nvim-snippy/lua/snippy/reader/snipmate.lua:110: in function 'read_snippets_file'
.../packer/start/nvim-snippy/lua/snippy/reader/snipmate.lua:195: in function 'load_scope'
.../packer/start/nvim-snippy/lua/snippy/reader/snipmate.lua:261: in function 'read_snippets'
...e/nvim/site/pack/packer/start/nvim-snippy/lua/snippy.lua:556: in function 'read_snippets'
[string ":lua"]:1: in main chunk
I was wondering if it would be possible to use custom options (aside from the w,i,b,A that are included). I'm imagining defining the option letter along with a lua function in a table in the setup()
call.
I should mention that I have a very specific use case in mind which is to only autoexpand certain snippets when in a "math" context in Latex. It makes it easy to define autosnippets related to math that don't expand while you are writing the body of the document. See here for examples.
From a quick look at your source, I think it could be as simple as checking for a letter that is not i,w,b,A, including it in option
, then looking up the corresponding function on expand.
It could also plug into can_expand
as a conditional.
Ultisnips has this functionality as custom contexts and Luasnip has this as condition.
The only variable that works is $VISUAL
.
I'm using nvim-cmp for autocompletion.
Am I missing something?
Hello again!
I searched your documentation, but I didn't find what I will just describe, so sorry if I misunderstood it.
Is there a function/command I could map on my configuration to have a list of all available snippets on the current filetype? If so, could you point me what is its' name?
E.g. of what I am looking for:
nnoremap <silent> <leader>sl <cmd>lua require'snippy'.list_snippets()<CR>| " (snippy) list snippets for current filetype
I am using honza/vim-snippets for a bunch of sensible default snippets. But I want to change the default C snippets. So I created a file ~/.config/nvim/snippets/c.snippets
, and changed some snippets, but the changes do not apply.
~/.local/share/nvim/site/pack/default/start
~/.config/nvim/snippets
The changed I made to the snippets apply
It still uses honza's vim snippets
No response
Currently, Snippy supports Neovim >= 0.5.0. Some features added in later versions, like Lua autocmds
, may improve performance and make the code more readable.
The idea is to make 0.7.0 the minimum compatible version, while possibly keeping a separate nvim-0.5.0
branch for those who aren't able to upgrade Neovim to a more recent version.
Neovim development is progressing at a fast speed, so keeping compatibility with outdated versions doesn't seem necessary.
Hey! Thank you for a really nice plugin. I hope your plugin will be popular.
I found a small bug in your plugin. I hope it won't be difficult to fix.
Thanks for creating this plugin. I really like the simplicity but still being able to use regex transformations ๐
I don't think this is supported in the lsp snippet standard (at least vsnip does not support it), but maybe you want to support it anyways.
snippet trig
triggered ${VISUAL:placeholder}
Basically if VISUAL is nil
(or ''
) use placeholder
instead.
The current behavior when using the w
option/modifier is different from how Ultisnips works, at least from what is present in their help file. Ultisnips seem to check for a pattern containing iskeyworkd
characters, whereas Snippy considers the whole string of characters before the cursor.
Also, the actual default behavior in Ultisnips seems to be different from the one set by the w
option. There needs to be further clarification on this.
Any help or insight greatly appreciated.
I'm using sourcekit-lsp for Swift. When using omni complete (eg, <c-x><c-o>
), selecting the result from the pop-up menu and then continuing to type seems to create a weird state in which triggering omni complete a second time enters the first result again.
mkdir swift_test && cd swift_test && swift package init --type executable
)nvim Sources/swift_test/swift_test.swift
swift_
and then use <c-x><c-o>
to open the pop-up menu for omni complete<c-n>
or <c-p>
to highlight the swift_test
module in the pop-up menu<c-x><c-o>
againAt step 5 swift_test
would be inserted as text.
At step 6 the pop-up menu would be dismissed.
At step 7 the inserted text would remain as is and the pop-up menu would open again.
At step 7 the text swift_test.
is replaced with sswift_test
. If you type two periods at step 6 instead of only one, swift_test.
is replaced with swswift_test
.
Here's my snippy config:
return {
"dcampos/nvim-snippy",
config = function()
local loaded, snippy = pcall(require, "snippy")
if not loaded then return end
vim.api.nvim_create_autocmd("CompleteDone", {
group = vim.api.nvim_create_augroup("snippy", { clear = true }),
callback = function() snippy.complete_done() end,
})
snippy.setup({
mappings = {
is = {
["<tab>"] = "next",
["<s-tab>"] = "previous",
},
},
})
end,
}
500ms is a definite delay. Why don't you use a repeating?
like this.
local function present_choices(stop, startpos)
local timer = vim.loop.new_timer()
timer:start(0, 100, vim.schedule_wrap(function()
if (candidates are exists) then
fn.complete(startpos[2] + 1, make_completion_choices(stop.spec.choices))
timer:stop()
timer:close()
end
end))
end
Hi,
I would like to expand $
to ${}
for shells (ft=sh):
snippet $
${$1}
That doesn't work. How do I achieve that?
It works fine for %
-> %{}
for ft=spec
Maybe this is already an option, but I haven't been able to figure out how to show the completion menu with several completions without having to write the entire trigger.
For example, suppose you have several snippets with the same prefix :
(e.g. :check:
, :arrow:
and other unicode symbols), so you may want to simply type :<Tab>
and show all of the relevant triggers in a completion menu. Is this possible? I noticed there is snippy.get_completion_items()
, but I don't think it is possible to use it (Unknown function: snippy#get_completion_items)
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.