6

I'm giving a second try to the fish shell. One thing that really annoys me is the "new" behaviour of Ctrl+w shortcut.

Consider following situation:

$ vim ~/.config/fish/config.fish

...having the cursor at the end of the line.

When you press Ctrl+w, following happens:

  • in bash: ~/.config/fish/config.fish is deleted
  • in fish: only config.fish is deleted

How can I make fish delete words that are separated by spaces only?

Ikar Pohorský
  • 4,617
  • 6
  • 39
  • 56
  • 1
    Im not familiar with fish shell, but this is often governed by a setting that defines what characters the line editor should consider a "word". e.g. in vim you have the `iskeyword` option variable and zsh has the shell variable `$WORDCHARS` . i.e. by default the zsh line editor does the thing you want, but personally I want the `^W` to stop on file path segments, so I edited `$WORDCHARS`. Sometimes the behaviour is specific to the line editor function you are calling too. – the_velour_fog Oct 06 '16 at 07:38

1 Answers1

14

"\cw" (in fish's notation) is bound to "backward-kill-path-component" (which bind \cw will tell you).

If you wish, you can bind it to something else, including input functions like "backward-kill-word" or any fish script - bind \cw backward-kill-word or bind \cw "commandline -rt ''" (which will remove the entire current token) or bind \cw backward-kill-bigword. See the bind documentation or bind --help for more information.

The difference between "word" and "bigword" here is that "word" will only go to the next non-word-character, which can be a "." or "/" or "-", among others, while "bigword" will truly go to the next whitespace character.

Note that the "bigword" functions have only been introduced in fish 2.3.0.

You can try these incantations in an interactive shell. If you decide to make it permanent, you'll need to add them to a function called fish_user_key_bindings.

osh
  • 42
  • 7
faho
  • 14,470
  • 2
  • 37
  • 47