4 ms·
CTRL+R is a bigger timesaver for me, but I could see this being useful if my memory weren't as keyword-based.
by alhirzel 5y ago
CTRL+R is a bigger timesaver for me, but I could see this being useful if my memory weren't as keyword-based.
- anyfoo 5y agoI scrolled down looking for someone mentioning Ctrl-R. I rarely write down shell command lines, even very complex ones, since I usually can quickly (very quickly) access them from my shell history with just a few keystrokes after Ctrl-R. It is the single most useful and important tool in my shell toolbox. It also obviates the need for many scripts and aliases I would otherwise write: Command lines can be (practically) arbitrarily long, and zsh at least has good multiline edit functionality (including just spawning an editor if you really need to). So there's a lot of "impromptu scripts", sometimes with different variations, in my shell's history. Some other features I would not want to miss (one from zsh, the other also available in bash, I think), albeit less critical: 1. Alt-. (Alt dot) immediately recalls the last argument passed to the last command line. I use this very very often. "mkdir long_name" followed by "cd long_name" is just one example. 2. Alt-q makes the currently typed command line disappear. But the next time you press enter to get a new prompt, even if you have entered a different command line, it will reappear. Super useful if you remember that you want to do something else before completing your command, without opening another terminal (some things like changing the current directory or env variables can't even be done in another terminal). This can even be done multiple times, it's a stack. Both need Alt behaving as "Meta" (a checkbox in macOS's Terminal.app for example), otherwise you can still type "ESC" followed by "." or "q", but that's two separate keystrokes.
- alhirzel 5y agoI do the exact same thing you do, and sometimes I think about enabling comments so I can have arbitrary tokens to CTRL+R toward. I have been using vi mode in zsh for so long, I never learned about Alt+.; thank you so much for introducing me! bindkey -M viins '\e.' insert-last-word https://stackoverflow.com/questions/34290179/get-last-argument-of-last-command-on-esc-zsh-vim-mode https://stackoverflow.com/questions/34290179/get-last-argume...
- mkl 5y agoAlt-. is in bash. I use it dozens of times per day, and its best feature is pressing it repeatedly to get arguments from earlier commands. Also if you press Alt-<number> before it, e.g. Alt-2, it inserts argument 2 (or whatever) from the previous command (0-indexed). Alt-q isn't in bash, at least by default, but it sounds pretty useful. I accomplish a similar thing with Alt-#, call the (now commented) command back with Up after however many other commands, then Alt-3 Alt-# will uncomment and run it (any number works there, but 3 is on the same key as #.