Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize word boundaries of Option-Delete (and other word related shortcuts) in macOS?

Is it possible to change the behavior of ⌥⌫ (option+delete) to include certain characters, like a period, as a word boundary?

For example, in some.variable, I would like ⌥⌫ to delete up to the period but it currently deletes the entire string. The screencast below shows the behavior using ⌥⇧←.

Screencast GIF

like image 444
keith.adams Avatar asked Nov 06 '22 05:11

keith.adams


1 Answers

I've looked high and low for a solution to this issue since the Cocoa-era, as far as I can tell there isn't a way to customize the "Option-Delete" word-delimiter (word-boundary) list. In addition to my own experiments, I'm basing this conclusion largely on the enormous number of MacOS keybinding modifications that can be found at the following 3 URLs (from oldest to most recently updated):

  1. Customizing the Cocoa Text System (circa 2006)
  2. DefaultKeybinding.dict (circa 2016, some info previously at the URL "lri.me")
  3. Keybindings -- BrettTerpstra.com (last updated 2018)

AFAIK, word-boundaries on MacOS default to whitespace and can't be changed. [This conclusion is invalid if there have been recent radical changes to MacOS text-input system].

It's no secret that many of the MacOS keyboard shortcuts are based upon eMacs-style 'keyboard-chording', as opposed to Vim-style 'modal-editing'. Indeed much of the Keybinding work cited above deals with remapping these chords. Vim of course is well-known for having a customizable delimiter list, it's the basis for differential word-movements between (for example) w, W and b and B (see vimhelp.org).

There have been a few extensions that have tried to bring 'Vim-style' editing to the MacOS, one of which is Karabiner. Karabiner (now re-written/updated to Karabiner-Elements) used to have a mode called "Ubiquitous_Vim". However without an OS-level 'hook' personal tests indicate that (for example) moving backwards via b and B works identically (i.e. there's no difference between a Vim word and a Vim WORD, see this StackOverflow post).

While I'm unable to find a way to modify the MacOS default 'word-boundary' list, if Vim-style editing does appeal to you, then you might try installing a project such as Vim-Anywhere, which enables you to 1. use a MacOS keyboard shortcut to open a Vim window whenever you need to enter text, and 2. will automatically copy your text to the MacOS System Clipboard when you close the Vim window. See this OSTechNix article: "How To Use Vim Editor To Input Text Anywhere" for more information.

like image 177
jubilatious1 Avatar answered Nov 13 '22 16:11

jubilatious1