helix icon indicating copy to clipboard operation
helix copied to clipboard

Allow chaining `find_next_char`, `select_textobject_around`, etc. together with other commands in keymaps

Open tmke8 opened this issue 3 years ago • 3 comments

There are quite a few commands that expect an argument in the form of a single character:

  • find_till_char
  • find_next_char
  • till_prev_char
  • find_prev_char
  • surround_add
  • surround_replace (this one even expects two arguments)
  • surround_delete
  • select_textobject_around
  • select_textobject_inner

However, it doesn't seem possible to chain these together with other commands in keymaps.

For example:

[keys.normal]
f = ["find_next_char", "collapse_selection"]

does not work as expected. The collapse_selection command seems to be completely ignored.

Similarly, this

[keys.normal]
C = ["select_textobject_inner", "change_selection"]

seems to execute the change_selection command immediately, before select_textobject_inner has finished.

My enhancement request is that if these commands with arguments appear in a keymap, they should first finish completely and then the next command in the list should be called.

tmke8 avatar Sep 28 '22 18:09 tmke8

I'm taking a stab at fixing this. I got a fix that works but needs a bit more work before I open a pull request.

kl avatar Oct 12 '22 17:10 kl

The ones related to select_textobject_inner are basically sub menus but the commands behind the items in the popup do not have command names themselves. For instance there really should be IMO a select_textobject_inner_word to do miw. I wonder if it would be a good idea to just name those commands and expose them for custom mappings.

mitsuhiko avatar Oct 15 '22 08:10 mitsuhiko

Although w, e and b, are great for selecting words automatically, I think f should change the default behavior like the key map below. In my case, It's more common for using without selecting. Is there any common case of using f with selection?

[keys.normal]
f = ["find_next_char", "collapse_selection"]

genepg avatar Nov 05 '22 04:11 genepg

Not sure why, but to chain some commands, sometimes they requires a :, and sometimes not: The following works fine for me. (Typing AltGr + d output ð on my French keyboard) Notice the erratic usage of :. It is a confusing behavior.

# Works fine: Duplicate line with AltGr + d
"ð" = ["extend_line_below", ":clipboard-yank", "open_below", ":clipboard-paste-before"]
# Doesn't work: Fail to load config (due to : on open_below)
"ð" = ["extend_line_below", ":clipboard-yank", ":open_below", ":clipboard-paste-before"]

webdev23 avatar Dec 31 '23 20:12 webdev23