1

I'd like Readline to consider words separated by dashes as single words, just as Vim does by default.

So for example, if I'm at the end of the line below and I type ctrl-W

cp long-filename-with-dashes

Readline would delete only dashes instead of the whole string until the space.

Is there any way to configure this without breaking other things?

zool
  • 267
  • 2
  • 13
  • 1
    possibly a duplicate http://unix.stackexchange.com/questions/27927/is-it-possible-to-configure-ctrl-w-delete-word – Valentin Bajrami Jul 19 '16 at 12:28
  • @val0x00ff That question is about using `/` as word separator, not exactly the same. I was able to find the right setting in there anyway, so thanks for pointing me there! – zool Jul 19 '16 at 12:45
  • oops, I read the question wrongly.. probably use `Esc+Backspace` or `Alt+Backspace` which is mapped to `backward-kill-word` – Sundeep Jul 19 '16 at 13:18

1 Answers1

1

I was able to achieve the desired behavior with this two lines in my bashrc:

stty werase undef
bind '\C-w: backward-kill-word'

Still no idea about possible side-effects though.

Edit: I found the proper way to set this in the inputrc without touching the bashrc and resorting to stty thanks to this article:

set bind-tty-special-chars Off

$if Bash
  \C-w: backward-kill-word
$endif

Update: Looks like bind-tty-special-chars breaks the behavior of w, e and <c-w> in Vim (probably among other things), so the best solution for me is to set stty werase undef in the bashrc and \C-w: backward-kill-word in the inputrc.

zool
  • 267
  • 2
  • 13
  • This wasn't working for me – I needed to use a capital W in the binding (i.e. `"\C-W": backward-kill-word`). – ash Dec 14 '17 at 12:17