5

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.

2
  • "Previous or start"? That doesn't make sense. Possibly you want Ctrl+b or Ctrl+a?
    – Mikel
    Commented 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.
    – manatwork
    Commented May 7, 2013 at 15:11

3 Answers 3

9

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:

  1. 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
    
  2. Use the vi mode (with bindkey -v) and use the B and W keys in normal mode just like in vi.

  3. In emacs mode (the default, reenabled with bindkey -e) like for bash, bind the corresponding widgets (vi-word-back and vi-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.

6
  • 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?
    – haimon
    Commented May 8, 2013 at 6:22
  • @haimon, Your shell must be either tcsh or zsh. Could you please find out (ps should tell you) and update your question? Commented May 8, 2013 at 6:55
  • Hi - it is tcsh according to ps.
    – haimon
    Commented May 8, 2013 at 8:24
  • 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)
    – haimon
    Commented May 8, 2013 at 11:30
  • @haimon. I don't think so. See the output of bindkey -l or man tcsh for the list of widgets. But you can use a macro (bindkey -s) to do the B followed by h. Commented May 8, 2013 at 12:05
0

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.

4
  • Usually also mapped to left arrow? :)
    – peterph
    Commented May 7, 2013 at 14:51
  • 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.
    – Bratchley
    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%+.
    – peterph
    Commented 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.
    – Bratchley
    Commented May 7, 2013 at 19:47
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .