JavaScript Template String Expression Surround #266
-
Hey all, I'm working on a custom surround/motion to quickly surround text within a string... So far I have this, and it works at the most-basic "proof of concept" level:
it works in visual mode and inner word motions and so on, with the I'd like to make it "smarter," but I'm not 100% sure what I'm doing more advanced stuff within Ideally I'm hoping to have something that functions like this: If the nearest surrounding pair is a string that is either if my normal mode keymap is If the nearest surrounding pair is not a quote of any kind, then the motion context should also create a template literal string around the proper context based on the motion: in normal mode if I type This last example I can think of would be a similar scenario as the previous example: if I have my cursor over the word |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
There currently isn't a way to detect what the nearest surrounding pair is, and it seems quite complicated to expose this information to the end user as a part of the plugin itself. However, here are some potential workarounds:
I think a better/marginally more complicated way is for you to use Tree-sitter to detect whether or not the node located at the cursor is a string, then use that information to selectively perform one of the two actions you mentioned above. I'll look into this more later, but don't currently have the time to experiment with it. |
Beta Was this translation helpful? Give feedback.
There currently isn't a way to detect what the nearest surrounding pair is, and it seems quite complicated to expose this information to the end user as a part of the plugin itself. However, here are some potential workarounds:
q
alias for targeting the nearest surrounding pair of quotes; your first case could be handled by first runningcsq`
(change surrounding quotes to`
) thenyziws
.S
thatadd
s{ "`${", "}`" }
to the buffer to handle your second caseI think a better/marginally more complicated way is for you to use Tree-sitter to detect whether or not the node located at the cursor is a string, then use that inform…