Live data from Hacker News

Shortcuts to Move Faster in Bash Command Line

teohm.github.com

11–20 of 26 posts

Re: Shortcuts to Move Faster in Bash Command Line

#11
post #10
post #8

My favorite tip is to stay in emacs mode, but whenever you have something "complicated" to do, use Ctrl-X Ctrl-E : it opens the current line in $EDITOR.

This is amazing. One of my persistent nuisances had been when and how to transition from command line to script. This makes it smooth!

Except all the line formatting gets lost in bash after executing the command; and it is automatically executed.

In zsh you still have the opportunity to inspect it once more when you leave the editor, and it maintains it's multiline format in the history.

Re: Shortcuts to Move Faster in Bash Command Line

#12
One of my most life-changing bash configurations is having history-search-backward / history-search-forward bound to the up and down arrows.

Put the following in your ~/.inputrc

  "\e[A": history-search-backward
  "\e[B": history-search-forward
  "\e[C": forward-char
  "\e[D": backward-char
  set show-all-if-ambiguous on
  set completion-ignore-case on 
Now if you type, say:

  cat 
You will cycle through commands in your history that start with the prefix "cat ".

Re: Shortcuts to Move Faster in Bash Command Line

#13
Note that you don't need to 'enable' the Meta key in Terminal on OS X.

By default, option does what it does in other programs, allowing you to type alternative characters. If you'd still like to keep that behaviour, you can send meta by pressing escape first -- Meta-b becomes escape, then b.

Re: Shortcuts to Move Faster in Bash Command Line

#15
Also install the awesome autojump: https://github.com/joelthelion/autojump

If I was previously sitting in directory:

'/home/user/code/github.com/cookbooks/cassandra/recipes'

and I wanted to jump back to that dir from anywhere on the file system I could just type 'j cass rec' and it would autocomplete and jump to this location. Super helpful.

Re: Shortcuts to Move Faster in Bash Command Line

#17

Also install the awesome autojump: https://github.com/joelthelion/autojump If I was previously sitting in directory: ' /home/user/code/github.com/cookbooks/cassandra/recipes ' and I wanted to jump back to that dir from anywhere on the file system I could just type ' j cass rec ' and it would autocomplete and jump to this location. Super helpful.

"cd -"

Re: Shortcuts to Move Faster in Bash Command Line

#18
Worth a mention is that you can customize how Readline handles these sorts of shortcuts in your ~/.inputrc file. For example, I use forward and backward by word far more often than by character, so I do this:

    $if Bash
        # various other stuff left out
        # easier back and forth by word
        "\C-b": backward-word
        "\eb": backward-char
        "\C-f": forward-word
        "\ef": forward-char
    $endif
For more examples and syntax, see http://docs.freebsd.org/info/readline/readline.info.Sample_I... and http://docs.freebsd.org/info/readline/readline.info.Readline....

Re: Shortcuts to Move Faster in Bash Command Line

#19
post #17

Also install the awesome autojump: https://github.com/joelthelion/autojump If I was previously sitting in directory: ' /home/user/code/github.com/cookbooks/cassandra/recipes ' and I wanted to jump back to that dir from anywhere on the file system I could just type ' j cass rec ' and it would autocomplete and jump to this location. Super helpful.

"cd -"

This is much more sophisticated than just jumping back to your previous directory. It keeps a weighted history of dir's you cd into most and uses those first for autocompletion etc.

Re: Shortcuts to Move Faster in Bash Command Line

#20
post #7
post #3

This is a description of the Emacs bindings, which are the default. Vi bindings are also available and can be enabled by adding set -o vi to ~/.bashrc. Peteris Krumins also has an article on bash command line editing with some extra information on completion: http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...

Beat me to it. (My first thought upon seeing the headline was, "wow, faster than vi mode?") I haven't actually put the set into my .bashrc yet, I just end up typing it when I realize I'm about to navigate a lot.

Semi-related, but what's the fastest vi way to get to the space right after the first word? For example, I might type

> ls /etc/foo/bar

and have my cursor at the end when I realize I want to type ls -l instead. I know there's got to be a faster way than what I'm currently doing, but I'm blanking.

(Yes, I know sometimes tacking on the command line switch at the end will work, but that's not true for all commands).

Post reply on HN