Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make fish shell delete words like bash does

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?

like image 985
Ikar Pohorský Avatar asked Oct 06 '16 07:10

Ikar Pohorský


1 Answers

"\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.

like image 186
faho Avatar answered Sep 22 '22 13:09

faho