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

Make (/[/{/T/F surrounds on visual line indent wrapped lines #8077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mogelbrod
Copy link
Contributor

@mogelbrod mogelbrod commented Nov 3, 2022

What this PR does / why we need it:

The surround plugin implementation is mostly great, but one thing I miss is a way to automatically indent the surrounded text in visual line mode. To my knowledge this wasn't supported in the original vim plugin either, but I'd argue that the current behaviour isn't exactly intuitive:

one
tw|o
three

VS{ currently results in:

one
{ 
two
 }
three

This PR changes the visual line mode behaviour of the surround keys that usually wrap the content with a space ((/[/{/T/F) to instead indent the surrounded line(s). The indentation for the delimeters are determined from the first line, with surrounded lines being indented one more level. With this PR the previous example will instead result in:

one
{
  two
}
three

Surrounds with )/]/}/t/f behave as before, as well as regular visual mode surrounds.

I also added Enter to the list of supported surround keys, which will wrap the selection in a multiline curly brace block (even outside visual line mode).

Additional examples

``` Home |Contact ``` `VkSTnav` results in: ``` Home Contact ```
one,
|two,

VkSFconsole.log<Enter> results in:

console.log(
  one,
  two,
)
one tw|o three

ysiw<Enter> results in:

one {
  two
} three

Which issue(s) this PR fixes

Special notes for your reviewer:

Two tests are failing - I'm struggling to get the cursor position to be where expected, would love to hear some ideas on how to solve it. I've seen that cursor position after surround actions have been problematic in general going by the number of issues referencing it.

…d lines

Also adds a new surround pairing for `<Enter>` which wraps the selection
in a curly brace block spanning multiple lines.
@mogelbrod
Copy link
Contributor Author

mogelbrod commented May 19, 2023

I'd like to take another look into this but given the cursor position problems I'd first like to hear if these changes are desired - @J-Fields what do you think?

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.

1 participant