5 ms·
In readline, ^U will only clear from the cursor to the start of the line, leaving anything on the right. ^K is the converse. I'm not sure you are speaking abou
by grive 10y ago
In readline, ^U will only clear from the cursor to the start of the line, leaving anything on the right. ^K is the converse.
I'm not sure you are speaking about readline though.
Another very useful thing I use daily is Alt-F/B, to move forward/backward in the line one word at a time. Control does the same, one letter at a time. D will delete an element instead.
- smhenderson 10y agoI also find Ctrl-W for backspacing a word at a time useful and also Ctrl-A/E for jumping to the beginning and end of the current line. Ctrl-L to clear the screen except the current line is also somewhat useful if you're at the bottom of the terminal screen and editing a long command line. Somewhat less useful but neat is Alt-U which will cause the current word under the cursor to become all upper case and Alt-C which is similar but changes the first letter to upper case and the rest of the word to lower case.
- Pete_D 10y agoThere's a lot of unexpected gems in the readline defaults. I recommend people try paging through "bind -p" in bash some time to see what's there. Personal favorites are C-r to search back in history and C-x C-e to edit the current command line in an external editor.
- wruza 10y agoIt is also very convenient to remap up/down keys to not just list history, but to do completion based on already typed characters: if [[ $- == *i* ]] then bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' fi (fix: grammar)
- nitrogen 10y agoDebian and Ubuntu typically have a commented-out mapping for this in /etc/inputrc as pgup/pgdn that I always enable in my ~/.inputrc. Editline supports something similar in .editrc IIRC.
- wruza 10y agoFunny, I became FreeBSD user because default .cshrc contained it (iirc). I didn't know about shells, readline, etc. back then. Wonder why they do not enable it on up-down by default, cause I see too many linuxoids around bored with up-up-up-enter up-up-up-enter to replay history, not even knowing that completion exists (along with at least ^K ^U ^C). What's the point to type a half-command and then replace input line with one from history if I press up? That somewhat resembles ugly cmd.exe, which every windows user imagines when someone says 'cli'.
- Symbiote 10y agoEmacs users will recognize many of the readline defaults -- unsurprisingly, given both are GNU software. I use "yank-last-arg" most often, which is M-. by default. $ mkdir abcd $ cd <M-.> On Zsh, I have M-, bound to "copy-earlier-word", which makes M-. M-, M-, cycle through the arguments to the previous command. In reading the manpage for Bash, which doesn't have this function, I've just found "history-search-backward", which searches through history to find commands based on what you've already typed. That will come in useful! $ bind '"\er":history-search-backward' $ bind <M-r> (Note that M-r is bound to "revert-line" by default, but I doubt I'll use that.) These functions are all listed, with explanations, in the Bash and Zsh manpages. Edit: As I see from another comment, a binding for "history-search-backward" to the Page Up key is in /etc/inputrc on Debian and derivatives.
- Sharlin 10y agoWeird, I'd have thought C-r is the one readline command everybody knows even if they know nothing else abour readline. Almost cannot imagine using command line without it. (Though there's also the "like tab-complete but from history" that I never really learned to use.)
- grive 10y agoAh! yes, at this point C-r is so entrenched in my habit, I didnt even realize it might be new to some. This is the shortcut to first learn when starting living in the command line.
- pixelbeat 10y agoYes some of these useful functions should be bound by default IMHO. Here are my settings to bind ctrl-{left,right} and {up,down} to more useful defaults. I.E. jump as the shell tokenizes the line, and search history for what's already typed respectively
- grive 10y agoTo add to that, C-P will go up in your history and C-N down. It is extra useful when using GDB in TUI mode (which is activated using C-x,a), which will capture your UP/DOWN arrow to navigate the source... Actually, just go read http://ss64.com/bash/syntax-keyboard.html http://ss64.com/bash/syntax-keyboard.html or something, once per day, integrate a new one each time, and you will improve your productivity on the command line (as well as comfort).
- Pete_D 10y agoFor gdb TUI, you can also use the 'focus cmd' and 'focus src' commands to choose which window gets to handle up/down. I usually keep the command window focused out of habit because the source window intercepts too many keys for my liking. Nice link - reminds me to try to use the history stuff like ! and ^ more.
- mwpmaybe 10y agoFor the vi-adherents out there, `set -o vi` will let you navigate your prompt and history with vi-like keybindings. I'm amazed by how many vi users don't know this.