Closed abenz1267 closed 2 years ago
Note to self: Check out vim-surround's docs
To minimize the number of posts I'll have to make in the breaking changes thread, I would like to get a complete, locked-in interface for naming all of the various keybindings. I propose the following, but would definitely like feedback:
Let the _cur
suffix denote that the mapping applies to the current line (not including leading/trailing whitespace), and the _line
suffix denote that the mapping will put the delimiters on new lines.
Consider the following names, with their vim-surround counterparts (all mappings in normal mode unless otherwise stated): |
nvim-surround key |
vim-surround mapping |
---|---|---|
insert |
<C-g>s in insert mode |
|
insert_line |
<C-g>S in insert mode |
|
add normal |
ys |
|
add_cur normal_cur |
yss |
|
add_line normal_line |
yS |
|
add_cur_line normal_cur_line |
ySs or ySS |
|
visual |
S in visual mode |
|
visual_line |
gS in visual mode |
|
delete |
ds |
|
change |
cs |
Bonus: As suggested by #79, add yt
for "you toggle"---While it would be easier to just cycle through an alias table (builtin ytq
and yts
), it would be nice to have ytb
to toggle between [
, (
, {
without needing to disable b
as an insert alias for (
. Perhaps this warrants a refactor that isolates single-char aliases from tabular aliases, which would also reduce some complexity.
CC: @andrewferrier @noahtheduke @akinsho since y'all seem to be pretty active (if you would like to not be tagged next time, feel free to just let me know). In a related vein I'm not quite sure how to get more community feedback on certain things, since discussions don't notify anybody :/ Also unsure if anybody actually checks the issues page unless they have a problem themselves.
Edit: Changed the normal mode mappings to normal
instead of add
; to show your support for the new naming scheme, leave a :heart: on this comment instead of :+1:
Update: Would it be better to change all instances of add
to normal
? That way we could have it be insert/normal/visual
for "adding" surrounds, as opposed to insert/add/visual
. I'm currently leaning towards this new suggestion, with add
being reserved as an "umbrella term" of sorts to refer to any of insert/normal/visual
.
Sorry for the late-ish work on this, but a mediocre version of this should be up and running on the linked branch add-more-keymaps
. It is mostly just a "proof of concept" that adds the keymaps yS
and ySS
from vim-surround, and there is much more work to be done. In particular:
insert
should be changed to normal
surround_spec.lua
to account for the new keymaps/corresponding tests, or delete the wrapper functions altogether. It might make more sense from a test-reader/adder perspective to just have :normal ysiwb
etc. everywhereThanks everybody for your patience while I work things out!
Note to self: Adding visual block support (to surround around the block on every line) probably makes sense to add in with this PR
Edit: Added in the latest commit.
@abenz1267 You should be able to try it out on branch add-more-keymaps
now by setting
keymaps = {
insert = "<C-s>",
insert_line = "<C-s><C-s>",
}
in your setup function. You can then enter <C-s>tdiv id="test div"
to insert an HTML pair.
Yes, that works, but indentation is broken.
Yes, I'm now aware of that. I'm trying to figure out a "sane" way to indent as per #76, and make it uniform/consistent across visual-line mode surrounds, as well as _line
suffixed surrounds. Thanks for pointing it out!
@abenz1267 The indentation should be fixed, but the code is quite bad. I'll need to fix that later before merging this branch into main
.
@rorj If you could test out the latest commit on add-new-keymaps
that would be very much appreciated, thanks!
I don't know if formatting after normal mode surrounds is going to be possible since formatting overwrites the last action (breaking dot-repeats), but I'll keep trying.
Edit: I've given up on this for now and have just merged it into main. If anybody cares enough about this, they can open up a new issue specifically for this case.
vim-surround let's you insert surroundings in insert-mode by pressing either
ctrl+s
orctrl+ss
wherectrl+ss
will also add a new-line in between the surroundings. This way you can easily create html-tags in insert mode. Just doctrl+s<div>
and you'll get<div>|</div>
.