Jorenar / miniSnip

Lightweight snippet plugin for Vim
MIT License
53 stars 8 forks source link

Expanding snippet jumps to placeholder outside of snippet template #12

Closed jmzagorski closed 3 years ago

jmzagorski commented 3 years ago

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.

  1. I type a snippet "rem" above my todaysDay function
  2. I hit <tab><tab> to expand my snippet
  3. The cursor jumps to the ${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 27

minisnip-expand-bug

Jorenar commented 3 years ago

That's why delimiters are configurable globally, per buffer and per snippet - to avoid conflicts with valid code.

I will later add boundaries for placeholder search, but I still recommend setting the delimiters differently from valid code.

PS. Final delimiters are no longer supported in favor of final tag

jmzagorski commented 3 years ago

Thank you, I did forget to update my config and forgot about per snippet config!

I wonder if no boundaries is a good thing in some situations. If you read :h template it gives you a strategy for template files, similar to your html/html.snip example. If those template files had snippet placeholders, then we could get a snippet when a new file is created and possibly jump to those placeholders if there was a normal mode mapping to do so.

That might be outside the scope of what you want to do since the same thing can be accomplished with a snippet, but with the extra step of typing the snippet name in the new buffer.

Jorenar commented 3 years ago

Good, then I'm closing the issue.

I regards to templates, are you perhaps referring to something similar to #13?

jmzagorski commented 3 years ago

Yes, #13 is exactly the solution, thanks for that tip! I guess boundaries may be a good idea at some point. In the meantime I will change my delimiters. Thank you again!