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

feat: wrap selection in tag & wrap selection in function call #12254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NikitaRevenco
Copy link
Contributor

@NikitaRevenco NikitaRevenco commented Dec 14, 2024

This PR adds 2 new keys under "Add Surrounding". Now you can use:

  • msx: Wrap selection with a tag
  • msf: Wrap selection with a function call

Both of those commands bring up a prompt to allow you to input what you want.

In the examples below, the whole word is selected and we input div.

Before

textContent

msx -- Surround selection with tag

<div>textContent</div>

msf -- Surround selection with function call

div(textContent)

It implements some functionality from #12055 because implementing "delete surrounding tag", "change surrounding tag" is more complicated

I think that wrapping selection in a tag and a function is a pretty useful feature to have, this doesn't add to many lines of code so I think it's worth adding it here.

A different PR could implement "delete surrounding function" and "change surrounding function" if necessary.

@pascalkuthe
Copy link
Member

Nit a fan of the prompt for editing in almost all circumstances.

This can be done with multi cursors; ms(i for function. I dont think that needs to be buktin at all (it saves one key and can be a custom keybinding).

For tags all you need is a function that creates the tags and inserts two cursor where the tag is missing. Not sure how I feel about that (a bit too special cased for HTML for my likingL but that one atleast offers something not yet easily available

@david-crespo
Copy link
Contributor

You inspired me to figure out how to do the tag thing with a macro keybinding.

function stag() {
  echo "<xxx>"
  cat
  echo "</xxx>"
}
[keys.normal.L]
t = "@|stag<ret>sxxx<ret>c"

I tried to do it all inline without the shell function, but I couldn't figure out how to get it to type a >< needs to be done as <<>, but <>> doesn't work the same way.

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

Successfully merging this pull request may close these issues.

3 participants