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: Improve move_cursor. #334

Merged
merged 12 commits into from
Jun 8, 2024
Merged

feat: Improve move_cursor. #334

merged 12 commits into from
Jun 8, 2024

Conversation

kylechui
Copy link
Owner

@kylechui kylechui commented Jun 5, 2024

This aims to add a "sticky" option for move_cursor, where "sticky" keeps the cursor "stuck" to whatever character the cursor was on before the surround action. See the unit tests in this PR for an idea of how exactly this would work.

One nice use case for this is dot-repeating with a sticky cursor, as one can do ysiw]. to surround a word with double brackets, whereas the old behavior would do something like hello[[]hello] (since the dot-repeat would surround the open square bracket).

Please react to show interest in this feature!

Replaces #289; is a partial solution to #281

TODO

  • Unit test inserting where the selection is entirely before the cursor.
  • Make it work for deletion/changing.
  • Document the new functionality.

@kylechui kylechui mentioned this pull request Jun 5, 2024
@kylechui kylechui linked an issue Jun 5, 2024 that may be closed by this pull request
1 task
@kylechui kylechui marked this pull request as ready for review June 7, 2024 00:23
@kylechui kylechui force-pushed the feat/improve-move-cursor branch from 91547c9 to b9453d6 Compare June 7, 2024 00:30
@kylechui kylechui mentioned this pull request Jun 7, 2024
1 task
kylechui added 9 commits June 6, 2024 19:55
Implements "end" and "sticky" for insertion.

TODO: Unit test inserting where the selection is entirely before the
cursor.
TODO: Make it work for deletion/changing.
TODO: Make it work for visual selections (edge case: block surround).
Remove work on `end`. Maybe work on it in the future if people actually
want it.
No default text-objects search backwards; it's better to leave this for
delete and change tests where we have lookbehind.
TODO: Visual mode, and unit test change.
@kylechui kylechui force-pushed the feat/improve-move-cursor branch from b9453d6 to 25f2e51 Compare June 7, 2024 02:56
lua/nvim-surround/buffer.lua Outdated Show resolved Hide resolved
lua/nvim-surround/init.lua Outdated Show resolved Hide resolved
kylechui added 3 commits June 7, 2024 10:14
Also break up namespaces for highlights vs. extmarks, to avoid
"collisions" when clearing one or the other.
If only Lua had linear types.
@kylechui kylechui merged commit ef592b5 into main Jun 8, 2024
4 checks passed
@kylechui kylechui deleted the feat/improve-move-cursor branch June 8, 2024 21:29
@miguelbarao
Copy link

Thanks for this very useful feature. Seems to be working fine in normal mode.
Is it possible to extend it to also work in visual mode? I get strange results when dot repeating in visual mode.

@kylechui
Copy link
Owner Author

kylechui commented Jun 10, 2024

Dot-repeating isn't a feature in Visual mode, because there are no "semantics" to repeat in visual mode---only hard-coded coordinates for the begin/end of a visual selection.

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.

Extend move_cursor to support a customize function
3 participants