How can I go back to the previous whitespace character

Discussion in 'Command Line' started by RickS, Feb 7, 2014.

  1. RickS

    RickS New Member

    Messages:
    5
    Likes Received:
    1
    Trophy Points:
    3
    For example, at the command line I have typed:


    vi abc-efg_hij.efg

    The cursor is at the end of the line. Esc-b takes me to the dot. Another esc-b takes me to the underscore. Another esc-b takes me back to the dash.

    Is there something I can press that will take me from the end of the line to the space after "vi"?
    DevynCJohnson likes this.
  2. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,070
    Trophy Points:
    113
    What shell (csh. bash, tcsh, ...) and terminal (xterm, kterm, ...) are you using?
    Haider92 likes this.
  3. RickS

    RickS New Member

    Messages:
    5
    Likes Received:
    1
    Trophy Points:
    3
    Oh, sorry. Bash and xterm.
  4. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,070
    Trophy Points:
    113
    It works for me.

    xterm.png
    Haider92 likes this.
  5. RickS

    RickS New Member

    Messages:
    5
    Likes Received:
    1
    Trophy Points:
    3
    Did you try it with dashes, underscores and periods, like my "vi abc-efg_hij.efg" example?
  6. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,070
    Trophy Points:
    113
    It works for me. What is your character encoding?

    xterm_2.png
    Haider92 likes this.
  7. RickS

    RickS New Member

    Messages:
    5
    Likes Received:
    1
    Trophy Points:
    3
    en_US.UTF-8
  8. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,070
    Trophy Points:
    113
    Hmmm. Mine too. What distro? I am using Ubuntu 13.10 (Saucy). I think it is some weird bug on your system. What if you tried reinstalling Xterm? Also, try using a different shell, like CSH. Just type "csh", "ksh", "tcsh", "ash", "dash", or what ever else you have. If the cursor moves back in a different shell within Xterm, then it is BASH, if not, then it is Xterm.
    Haider92 likes this.
  9. RickS

    RickS New Member

    Messages:
    5
    Likes Received:
    1
    Trophy Points:
    3
    Thanks a lot for the help! Maybe somebody else who had the same issue will chime in.
  10. DevynCJohnson

    DevynCJohnson Well-Known Member Staff Member Staff Writer

    Messages:
    1,331
    Likes Received:
    1,070
    Trophy Points:
    113
    Do the arrow keys work in other terminals to move the cursor (like konsole, gnome-terminal, etc.)?
    Haider92 likes this.
  11. KenJackson

    KenJackson Active Member

    Messages:
    129
    Likes Received:
    28
    Trophy Points:
    28
    Have you set your shellopts to emacs or vi? Execute this command to see:
    Code:
    set -o | egrep 'emacs|vi'
    Emacs is on by default, so if you haven't changed it you can search backward for the space character.
    CTRL-R <space>

    To continue searching press CTRL-R again. Once you get to where you want to be, you have to stop the search before you start editing. You can do that with cursor movement keys (arrows, CTRL-F, CTRL-B, probably others).

    If you're more comfortable with vi than emacs, you might experiment with this. I haven't tried it, but then I'm not comfortable with vi.
    Code:
    set -o vi
    DevynCJohnson likes this.
  12. MikeyD

    MikeyD Active Member

    Messages:
    232
    Likes Received:
    112
    Trophy Points:
    43
    In shell:
    CTRL -A - Will bring you to the beginning of the line.

    In vi:
    W and B (as opposed to w and b) will jump between words using only whitespace to differentiate and will ignore dots dashes and the like, which are used by the lower-case equivalents.

    Not sure if that works on the command-line though with shellopts set to vi as i've never tried.
    Essentially if you just wanted to use Ctrl commands you could use:
    Ctrl - A - Beginning of line
    Esc - F (or Ctrl - F x2) - Move forward one word (Ctrl F moves one letter)
    Ctrl -K - Deletes everything after the cursor
    Last edited: Feb 27, 2014

Share This Page