elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.67k stars 299 forks source link

Make insert mode word-based keybindings (alt+f, alt+b, etc.) assume *small* words by default #723

Open kwshi opened 6 years ago

kwshi commented 6 years ago

Not a bug, but a suggestion.

Currently, Alt+f and Alt+b keybindings correspond to edit:move-dot-left-word and edit:move-dot-right-word, which respectively move the cursor left and right by a WORD, which is a contiguous sequence of non-whitespace characters. Instead, I propose mapping those keys to edit:move-dot-left-small-word and edit:move-dot-right-small-word by default, which move the cursor relative to a word, which is a contiguous sequence of alphanumeric characters, or a contiguous sequence of non-alphanumeric characters, separated by whitespace.

This would be a desirable default because it would essentially match the default behavior of readline bindings in other popular shells (i.e. bash and zsh), and also approximately match word-movement behavior in vim and emacs.

Furthermore, in most situations I have come by, I have found it generally preferable to edit and move by small-word rather than by WORD. As an example, if I want to manipulate a long file path, or a long URL, it would be more convenient to be able to use Alt-b to hop my cursor to the middle of the path/URL, where current behavior only allows me to move to either the beginning or the very end of the string, from which I would need to navigate by-character (i.e. arrow keys, or equivalent) to the middle of the string.

quexxon commented 1 month ago

I'll second this. I have the following in my startup script to get the best of both worlds - fine-grained by default with opt-in to coarse-grained using the shifted variants.

{
  var bind~ = {|k f| set edit:insert:binding[$k] = $f }

  bind Alt-b $edit:move-dot-left-small-word~
  bind Alt-B $edit:move-dot-left-word~
  bind Alt-f $edit:move-dot-right-small-word~
  bind Alt-F $edit:move-dot-right-word~
  bind Alt-d $edit:kill-small-word-right~
  bind Alt-D $edit:kill-word-right~
}