jorengarenar / minisnip Goto Github PK
View Code? Open in Web Editor NEWLightweight snippet plugin for Vim
License: MIT License
Lightweight snippet plugin for Vim
License: MIT License
does it not need configuration from .vimrc ?
Hi is it possible to expand without file snippet?
When I would have separate source of completion, omnicomplete for example:
Scenario: Breaker guesses a word
Given the Maker has chosen a word
When the Breaker makes a guess
When the <{}> makes a guess (c)
Then the Maker is asked to score
(c) - where cursor is placed after line insert.
I want to jump to placeholder and fill it in as in snippet from file.
If foo.snip
contains:
test
And the buffer looks like (*
is the cursor position):
foo*
After the latest commit (11bc4fd), triggering the snippet expansion results in:
footest*
When it should be:
test*
First off, great job on a simple yet elegant snippet solution! I had ultisnips for a while, but never used all of its features so i removed it from my vimrc.
I was not sure the best way to fix this issue. I changed the config to the below settings:
let g:miniSnip_opening="{"
let g:miniSnip_closing="}"
and believe the s:final_pattern
logic never fires because an exception is not thrown within this try/catch https://github.com/Jorengarenar/miniSnip/blob/master/autoload/miniSnip.vim#L114 because @{}@
is a valid placeholder with the new opening/closing configuration.
With the following snippet, the first placeholder is skipped and the cursor jumps straight to the final placeholder without removing it:
? Option parsing
while getopts "<{}>" option; do
case $option in
<{}>
esac
done
shift $((OPTIND - 1))
Which results in this:
while getopts "" option; do
case $option in
<{}>
# ^---- cursor here
esac
done
shift $((OPTIND - 1))
It may be related, but if I give the first placeholder a default value, it is filled in and instead a selection is made from the start of the first placeholder to the start of the next placeholder.
Hi I have prepared pull request #23
My vim details:
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 28 2022 16:22:51) / ArchLinux
But at the moment I have problems with expanding in ruby code.
It consumes dot. For example:
With following snippet:
? select inline
select { |<{element}>| <{+}> }
Sample code
array.sel<expand>
Result
select { |<{element}>| <{+}> }
And sometimes it does not expand at first time.
I am using ddc to support complete menu.
Other settings
let g:miniSnip_dirs = [expand('~/.vim/miniSnip')]
let g:miniSnip_trigger = '<c-s>'
let g:miniSnip_extends = {
\ "arduino" : [ "cpp", "c" ],
\ "cpp" : [ "c" ],
\ "markdown" : [ "html" ],
\ "tex" : [ "plaintex" ],
\ "bash" : [ "sh" ],
\ "typescript" : [ "javascript" ],
\ "typescriptreact" : [ "javascript" ],
\ }
let g:miniSnip_expandpattern = '\v[a-zA-Z0-9_-]+%'
Hi,
first of all, thanks for letting me get rid of UltiSnips.
I have found the following issue:
Whenever I expand a snippet, a space is inserted after the expansion.
This is especially annoying as it constantly produces trailing white space.
Is this a known thing? If so, how can I avoid it?
Thanks!
With a snippet like this:
? TryFrom implementation
$ `{{` `}}`
impl TryFrom<{{&str}}> for {{Type}} {
type Error = {{anyhow::Error}};
fn try_from(input: {{~1}}) -> Result<Self, Self::Error> {
todo!()
}
}
After expanding and confirming the value for the first placeholder {{&str}}
, the buffer looks like:
impl TryFrom<&str> for Type {
type Error = {{anyhow::Error}};
fn try_from(input: {{~1}}str) -> Result<Self, Self::Error> {
todo!()
}
}
Maybe the substitution needs to have "very nomagic" (:h /\V
) enabled?
When expanding snippets with <tab>
indents, they are expanded using the value of 'tabstop'
, regardless of the 'smarttab'
setting.
After reading the help on 'ins-smarttab'
, it appears that <tab>
should use 'shiftwidth'
to expand <tab>
's when 'smarttab'
is on (it is for me), and 'tabstop'
otherwise.
I have not had the opportunity to look into this yet, but I thought I would let you know about an issue I am running into. Whenever my snippet value has a \ or a /, the reference snippet does not expand properly. I included the animation to show you. My plugin configuration is below as well. Are you able to replicate this issue?
let g:miniSnip_dirs=[ $MYVIMRCPATH . '/after/mysnippets' ]
let g:miniSnip_ext="snippet"
let g:miniSnip_opening="${"
let g:miniSnip_closing="}"
let g:miniSnip_delimChg="`"
Hi,
I just got started with joereynolds/vim-minisnip and a decent set of snips from @Gavinok's dotfiles .
It's a wonderful plugin, elegantly simple and doesn't get in my way.
Then I found miniSnip. I would much rather build my snips collection for this modern version. So I am giving it a try.
I installed it with Plug 'Jorengarenar/miniSnip'
and configured as follows:
let g:miniSnip_trigger = '<C-g>'
let g:miniSnip_dirs = [ '~/.vim/miniSnip' ]
Per the readme, I created a file foo.snip
and placed it in ~/.vim/miniSnip/all
.
When I type foo
and then hit <C-g>
, I get the error message miniSnip: no snippet with that name
. I am totally not a vimscript coder, but from looking at the miniSnip#trigger()
function, it's pretty clear (I think) that it doesn't matter what is in the file: if it is not found, it isn't parsed.
I cannot figure out what I've done wrong -- I must be missing something simple.
Also, a question. Once I resolve the snip loading issue, the snips I have are for the joereynolds version and therefore have a different syntax from miniSnips. Is miniSnips backwards compatible?
If it is not, and assuming all else is tests well with miniSnip, I will likely convert the older snips to the new syntax. Seems like a small collection like this would make a good addition to miniSnip -- I would be happy to do a pull request if it sounds like such a thing would be useful.
Many thanks for your work on this plugin!
--Phil
Hey since commit 2493202 (Simplify code a bit) indentation and commenting in snippets is broken.
/**
* {{+Class description+}}
*
* @version {{+Version Number+}}
* @author {{+!g:name+}}
*/
{{+private+}} class {{+@classname+}} {
// fields
private {{+type+}} {{+@varname+}};
// Class Constructors
public {{+@classname+}}({{++}}) {
{{+/* Set Args */+}};
}
/**
* @return {{+@varname+}}
*/
public {{+@type+}} get{{+@varname+}}() {
return {{+@varname+}};
}
/**
* @param {{+@varname+}}
*/
public void set{{+@varname+}}({{++}}) {
{{+`'this.'.@varname.' = '.@varname+}};
}
}
now becomes
/**
* * {{+Class description+}}
* *
* * @version {{+Version Number+}}
* * @author {{+!g:name+}}
* */
{{+private+}} class {{+@classname+}} {
// fields
// private {{+type+}} {{+@varname+}};
//
// // Class Constructors
// public {{+@classname+}}({{++}}) {
// {{+/* Set Args */+}};
// }
//
// /**
// * @return {{+@varname+}}
// */
// public {{+@type+}} get{{+@varname+}}() {
// return {{+@varname+}};
// }
//
// /**
// * @param {{+@varname+}}
// */
// public void set{{+@varname+}}({{++}}) {
// {{+`'this.'.@varname.' = '.@varname+}};
// }
//}
I am using skeleton files to template certain filetype files. I would like to move these to use miniSnip functionality for vimscript evaluation. Is it possible to trigger a certain snippet from an autocmd BufNewFile
?
The current version of miniSnip works just as it should on my arch and manjaro machines. However, only on macos
(Ventura 13.2.1), when I try to insert a snip, I get this error:
E117: Unknown function: miniSnip#trigger
I am installing as follows:
Plug 'Jorengarenar/miniSnip'
The only configuration settings are:
let g:miniSnip_trigger = '<C-g>'
let g:miniSnip_dirs = [ '~/.vim/minisnip_modern' ]
I suspect the problem has something to with the mixed-case name of miniSnip
. In its typical configuration, macos preserves case, but it does not differentiate a mixed case from all lower case file name.
This just sounds so strange that I had to run the following experiment:
On manjaro:
echo "doc 1" > doc.txt
echo "doc 2" > Doc.txt
ls
doc.txt Doc.txt
cat doc.txt
doc 1
cat Doc.txt
doc 2
On macos:
echo "doc 1" > doc.txt
echo "doc 2" > Doc.txt
ls
doc.txt
cat doc.txt
doc 2
As you would expect, on a real linux system, doc.txt
and Doc.txt
are completely different files, and so both are preserved and have their own content. On macos, doc.txt
and Doc.txt
are seen as the same file. Thus we end up with only one file, and it has the content of the second command (macos overwrote the first file)
I don't know enough about how vim plugins are structured to explain the precise mechanism for the failure to find the function, but the case-insensivity on macos strikes me as a possible culprit.
÷÷÷
Hello,
The problem I am having is detailed below. In summary, when I expand a snippet, my cursor jumps to a placeholder that is outside the snippet template. I would be happy to look into it when I have the time.
My configuration:
let g:miniSnip_opening="${"
let g:miniSnip_closing="}"
let g:miniSnip_finalOp="{0"
let g:miniSnip_finalEd="}"
Below is an animation that shows my problem.
todaysDay
function<tab><tab>
to expand my snippet${value}
on line 22, which is outside the snippet template. This is not a placeholder, but a valid piece of javascript. The snippet template form the javascript comment is put in the correct place on line 27When I try to create more than one snippet for a given filetype by calling :MiniSnip foo
I get the following error:
Error detected while processing function miniSnip#edit:
line 7:
E739: Cannot create directory: ~/.vim/miniSnip/asm
This only happens when there is already a snippet defined for the given filetype.
This is the output of git log
inside ~/.vim/bundle/miniSnip
commit 3ab20f06feb15ccd3a2fedb8d22113dc5a521743 (HEAD -> master, origin/master, origin/HEAD)
Merge: 5a3c103 bc693cb
Author: Jorengarenar <[email protected]>
Date: Thu Apr 22 04:06:27 2021 +0200
Merge branch 'master' of github.com:Jorengarenar/miniSnip
commit 5a3c103d044f9064f8839c31a0c4bf49ac7a4989
Author: Jorengarenar <[email protected]>
Date: Thu Apr 22 04:05:41 2021 +0200
Fix creating snippets via :MiniSnip command
So it seems there was an attempt at fixing this issue.
I've noticed that there seems to be one particular case that is not indented correctly.
Specifically, I have the following snippet for HTML files:
<<{}>>
<{}>
</<{~1}>>
However, when I expand this, instead of the expected result (using div
as an example):
<div>
|
</div>
I get the following:
<div>
|
</div>
I'm not exactly sure why this particular case indents incorrectly, but I speculate it is related to the name of the closing tag itself being a placeholder.
When 'r' is included in formatoptions
, the following snippet:
? Shebang
#!/usr/bin/env sh
<{+}>
Expands to this:
#!/usr/bin/env sh
#
I'm curious why this happens. It doesn't happen if I type that content in directly.
If something follows snippet keyword, it is appended at the end of next line instead of the end of snippet.
The following snippet:
? tag
$ `{{` `}}`
<{{name}}{{}}>
{{+}}
</{{~1}}>
Leaves the last line indented:
<foo disabled>
text
</foo>
I thought it might be autoindent, but turning that off didn't seem to affect it, and nothing seemed relevant in the formatoptions. Any ideas?
this plugin https://github.com/mbbill/code_complete is good and tiny, But not good for building our language snip libs and not update now.
Maybe minisnip can borrow its advantages
If a snippet file foo.snip
contains something like (where <tab>
is a tab character):
<tab>test
And the buffer contains (where *
is the cursor position):
foo*
And 'expandtab'
is set, the buffer will be the following after expansion:
<tab>test
Where it should be (given a 'shiftwidth'
setting of 4
:
test
in addition to <{~1}>
it would be nice to allow us to use variables to store values we enter and recall them multiple times. the way I wal thinking would be store a value with <{>varname}>
then recall it with <{<varname}>
there may be a better notation.
Hello, I found a possible bug. Can you please help me?
I have the following snippet for some assembly code on a learning machine called ULM:
? create function call
// <{fname}>()
subq 8, %sp, %sp
ldzwq <{~1}>, %call
jmp %call, %ret
addq 8, %SP, %SP
All the whitespaces are tabs.
Now if I use this like this
call<tab>
everything works fine. But when I first type a tab and then type call<tab>
the placeholder <{~1}> does not get replaced but just deleted.
call<tab>
First of all, thank you very much for this great plugin!
I noticed that i_<C-x><C-u>
shows the snippets for the associated filetype, but it is also open a split as shown below:
This is my configuration:
let g:miniSnip_opening = '{{'
let g:miniSnip_closing = '}}'
let g:miniSnip_local = 'miniSnip'
I'm not sure if this behavior was enabled by default on purpose, however, I was wondering if it can be disabled. I don't really need a preview, so it would be enough to see the suggestions in the pop up menu as usual.
Thanks!
Hello. Could it work with mucomplete?
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.