I'm looking for a keyboard shortcut in tcsh
to move the cursor back to the previous blank: not ESC+B which takes me back one word (for instance, in a path argument, to the previous path component) - I want to get to previous space or start of current path.
-
"Previous or start"? That doesn't make sense. Possibly you want Ctrl+b or Ctrl+a?– MikelCommented May 7, 2013 at 14:46
-
I think haimon wants to jump in “asd efg/hij” from letter “j” back to letter “e”. (Ctrl-a jumps to “a”, Alt-b jumps to “h”, Ctrl-b moves to “i”.) Maybe Alt-Ctrl-],space is the closest.– manatworkCommented May 7, 2013 at 15:11
3 Answers
If you mean keyboard shortcut at the prompt of interactive bash
shells, you could bind the shell-backward-word
and shell-forward-word
to some sequence of characters sent upon some key or combination of key presses.
Like if pressing Ctrl-Left sends the sequence \e[1;5D
on your terminal like it does in xterm
, you could do:
bind '"\e[1;5D": shell-backward-word'
bind '"\e[1;5C": shell-forward-word'
Note that it does not jump from blank to blank but considers shell quoting. So for instance in a line like
echo "foo 'bar baz' blah/bleh bloh
^ ^ ^ ^
It would jump to the locations marked above.
Edit: for tcsh
, you have three options:
Use the equivalent to the
bash
definition above, either in~/.cshrc
or in/etc/csh.cshrc.local
to give all users the benefit.bindkey '\e[1;5D' backward-word bindkey '\e[1;5C' forward-word
Use the
vi
mode (withbindkey -v
) and use theB
andW
keys in normal mode just like invi
.In
emacs
mode (the default, reenabled withbindkey -e
) like forbash
, bind the corresponding widgets (vi-word-back
andvi-word-fwd
):bindkey '\e[1;5C' vi-word-fwd bindkey '\e[1;5D' vi-word-back
Note that those are like vi
's B
and W
, so they're for jumping between blank separated words, not shell tokens (like quoted strings) like in the bash
solution above.
-
Yes Stephane this is what I'm looking for ! but I dont have bind command in my shell, I found bindkey and it does not understand it...any idea?– haimonCommented May 8, 2013 at 6:22
-
@haimon, Your shell must be either
tcsh
orzsh
. Could you please find out (ps
should tell you) and update your question? Commented May 8, 2013 at 6:55 -
-
Hi - is there a VI shorcurt to jump to previous space or start of text (aaa bb/cccc - jump from en of line to space between b and a)– haimonCommented May 8, 2013 at 11:30
-
@haimon. I don't think so. See the output of
bindkey -l
orman tcsh
for the list of widgets. But you can use a macro (bindkey -s
) to do theB
followed byh
. Commented May 8, 2013 at 12:05
I think you're wanting CTRL-B
which in bash moves the cursor back one character. CTRL-f
will then move you back forward. Here is a quick reference for these shortcuts.
-
-
Depends on what type of Unix or what distribution of Linux the OP is on. Arrow keys aren't always mapped, that's something you usually only see on the more user-friendly Linux distros. Commented May 7, 2013 at 14:53
-
Sure, that's why I wrote usually. I think percentage of live systems that have it like this will be 90%+.– peterphCommented May 7, 2013 at 17:53
-
I have about 50 Solaris servers that don't fit that description. Traditional Unix still has a large install base that GNU/Linux as a whole is just now approaching parity with. Commented May 7, 2013 at 19:47
"ESC-left-arrow : go to beginning of left word" bindkey ^[^[[D vi-word-back
for example: cd a/b/c/d ESC+left will take you from end of line to the space between "cd" and "a"