4 ms·
Shortcuts to Move Faster in Bash Command Line
- vlandham 14y agoVery similar list here: http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-productivity/ http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-pro... which includes some other nice shortcuts - like ctrl + xx
- julian37 14y agoThis 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-sheet/ http://www.catonmat.net/blog/bash-emacs-editing-mode-cheat-s...
- alxndr 14y agoBeat 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.
- chimeracoder 14y agoSemi-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).
- wumpushunter 14y agoShift-T (the opposite of up`t`o) and then `s`. You can hit `;` if there are multiple incidences of 's'.
- weaksauce 14y agojj0W that should work for commands without spaces in them. I remap jj to escape so it is faster than moving my hand. in ~/.inputrc set editing-mode vi $if mode=vi #normal mode set keymap vi-insert "jj": vi-movement-mode $endif
- darkstalker 14y agoWhat's wrong with using the arrow keys?
- Adrock 14y agoIt amounts to significantly less hand and finger movement.
- csmatt 14y agoExactly. That's why I'm such a fan of emacs. The closer I stay to the home-row, the better. Also, 'Ctrl + p' and 'Ctrl + n' will navigate through your command history. I do love 'Ctrl + r' for searching through it, too.
- lelf 14y agoBash is out of place here actually, they are just general readline's and work in many places http://cnswww.cns.cwru.edu/php/chet/readline/readline.html http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
- emillon 14y agoMy 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.
- Evbn 14y agoThis is amazing. One of my persistent nuisances had been when and how to transition from command line to script. This makes it smooth!
- mhitza 14y agoExcept 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.
- jashmenn 14y agoOne 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 <UP ARROW> You will cycle through commands in your history that start with the prefix "cat ".
- digisign 14y agoI use this with the fish shell, and it seems to do a better job of searching than the ^R in bash. Not sure of the difference, but I think bash only searches from the front of the string.
- pieter 14y agoNote 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.
- username3 14y agoIs there a redo to go with undo?
- res0nat0r 14y agoAlso install the awesome autojump: https://github.com/joelthelion/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.
- jameswyse 14y agoIt's also worth noting that in OSX many of these shortcuts work anywhere you can enter text. I use ctrl+a/ctrl+e all the time.
- telemachos 14y agoWorth 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_Init_File.html http://docs.freebsd.org/info/readline/readline.info.Sample_I... and http://docs.freebsd.org/info/readline/readline.info.Readline_Init_File.html http://docs.freebsd.org/info/readline/readline.info.Readline....
- Scaevolus 14y ago$_ and !$ are additional ways to get the last argument of the previous command. http://samrowe.com/wordpress/advancing-in-the-bash-shell/ http://samrowe.com/wordpress/advancing-in-the-bash-shell/ is a good list of extra tips