Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tabstop exclusively in an interpolation #1511

Open
alexandersokolow opened this issue Dec 28, 2022 · 5 comments
Open

Use tabstop exclusively in an interpolation #1511

alexandersokolow opened this issue Dec 28, 2022 · 5 comments

Comments

@alexandersokolow
Copy link

alexandersokolow commented Dec 28, 2022

Hi, I wanted to create a snippet for react hooks, which usually go by the naming convention of "useName".

It's easy to do if I have use the uncapitalized version somewhere else, but if I only want to have the capitalized version of my input, it won't prompt me for the first tabstop & just complete the snippet with an empty input.

I.e., look at this snippet (where capitalize_first is a function doing exactly what the name says haha):

use`!p snip.rv=capitalize_first(t[1])`

It will complete immediately without prompting me for text & just return "use"

The following works:

$1
use`!p snip.rv=capitalize_first(t[1])`

But it will give me:
name
useName

instead of just:
useName

How can I make it just give me the useName?

Btw, if you wondering whether this simple snippet isn't pretty useless, I actually want to generate the following:

const useName = () => {
  return {};
};

export { useName };
@SirVer
Copy link
Owner

SirVer commented Jan 1, 2023

how should the snippet know which Name you want to use?

@alexandersokolow
Copy link
Author

alexandersokolow commented Jan 3, 2023

I imagined the following: I type my snippet shortcut (rh for react hook or something like that), click tab to get the boilerplate code without the name & when I start typing, it will take the text I type and capitalize it. Kind of like a normal snippet with just 1 tabstop, but the text from this tabstop should instantly get capitalized. I.e., once I type the first letter "n" (for name) it should give me an N instead of an n.

So, it would still have the tabstop, but that tabstop would only be found "inside" of the interpolation.

@SirVer
Copy link
Owner

SirVer commented Jan 8, 2023

Ah, this is difficult to do, since UltiSnips cannot control the text that Vim types into the buffer. And it would confuse Vim a lot to modify text "under it" so to speak, so unfortunately this will not be easy to implement.

@alexandersokolow
Copy link
Author

Hmm, guess there's no simple built-in solution for this then, maybe I'll have a try at implementing it at some point.

Could you elaborate on what you mean by "it cannot control the text that Vim types into the buffer"?
Isn't it removing (e.g. "uh") and inserting (e.g. "useHook") text from / into the buffer every time I expand a snippet?

@SirVer
Copy link
Owner

SirVer commented Jan 12, 2023

@alexandersokolow Patch would be very welcome!

What I mean is that if you type a character, Vim is interpreting your input and puts the char in the buffer. Only after, UltiSnips gets a chance to modify the buffer. If it overwrites what Vim just put into the buffer, vim gets really confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants