Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Normally, Ctrl-w deletes back to the last whitespace.

Is it possible to configure it to use additional characters, such as /?

Edit: To be more clear: I don't want to configure the key for it, I want to have the deletion stop on / aswell.


vim /foo/bar^W
vim /foo/
share|improve this question

4 Answers 4

You should be able to use Esc, then backspace to delete words delimited by slashes.

You can change this by putting this in you .bashrc:

bind '\C-f:unix-filename-rubout'

Now use Ctrl+f to do what you want.

share|improve this answer
thanks, that's the command that works. is there a way to overwrite the command of C-w? If I change it to C-w:..., the default behaviour of deleting to the next space still kicks in. On a different key (like F) if works fine. – SkaveRat Jan 16 '12 at 23:37
I don't think ctrl-w is managed by the shell alone. It may be managed by the tty also. What are your tty setting shown by stty -a? do you have control-w as default char for werase? If you remove that setting from tty, with comman stty werase undef, does then bash works as expected? – eppesuig Dec 14 '12 at 13:19

With bash you can get the desired effect, putting the following in your ~/.bashrc file:

bind '"\C-w":backward-kill-word'

Hit CTRL+V and the your key combination to see what it looks like for your terminal emulator. For instance CTRL+bksp can be interpreted different on different terminals e.g. ^H or ^?. The ^ character is the same as CTRL.

share|improve this answer
I think I wasn't specific enough with my question. I wanted to have / as an additional stop-character, not a way to bind the delete-word-command on an other key. I edited my question – SkaveRat Dec 30 '11 at 13:28
Using backward-kill-word binded to \C-w, it will erase backwards to the last given forward slash if present in a word and it will erase words delimited by whitespace. This is not what you wanted? – user13742 Dec 30 '11 at 15:34
My system uses ^F - but using "\^F" in the script above doesn't work – SkaveRat Jan 16 '12 at 18:53
The Ctrl character is written \C in the script and not \^. – user13742 Jan 16 '12 at 23:41

What worked for me was to add the following lines to my .bashrc

stty werase undef
bind '\C-w:unix-filename-rubout'

You need the undef line otherwise bash ignores your new binding for C-w

share|improve this answer
It should be noted that stty werase undef will stop you from using C-w in any program (bind will allow you to use in readline) – 0fnt Jul 13 at 16:58

For this specific issue, you can also use:

Alt + Backspace

$ cd /home/me/test/a_dir/    # Alt + Backspace
$ cd /home/me/test/          # Alt + Backspace
$ cd /home/me/               # ...

Good reference: Adventures with bash's word erase

share|improve this answer
Awesome! Most other answers suggest rebinding Ctrl+w or Ctrl+b or something to unix-filename-rubout, but it's so much better that there's a built-in binding: M-backspace (Alt+backspace or Esc backspace) – Colin D Bennett Mar 12 at 17:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.