11 ms·
I highly recommend everyone learn the readline keys. They apply everywhere, in chrome, messengers, etc. They're the most valuable hotkeys that I've learned othe
by Exuma 6y ago
I highly recommend everyone learn the readline keys. They apply everywhere, in chrome, messengers, etc. They're the most valuable hotkeys that I've learned other than learning vim.
I set them as the Message Of The Day in my .zshrc (or .bashrc if you don't use zsh) until I memorized them. <c-f> is genric formatting for hotkeys, where c stands for control and you type "f" at same time.
IMPORTANT: For these to be level extremely effective you MUST REMAP your caps lock key to a control key. System Prefs > Keyboard > Modifier Keys button at bottom right
# MOTD
function echo_color() {
local color="$1"
printf "${color}$2\033[0m\n"
}
echo_color "\033[0;90m" "c-f Move forward"
echo_color "\033[0;90m" "c-b Move backward"
echo_color "\033[0;90m" "c-p Move up"
echo_color "\033[0;90m" "c-n Move down"
echo_color "\033[0;90m" "c-a Jump to beginning of line"
echo_color "\033[0;90m" "c-e Jump to end of line"
echo_color "\033[0;90m" "c-d Delete forward"
echo_color "\033[0;90m" "c-h Delete backward"
echo_color "\033[0;90m" "c-k Delete forward to end of line"
echo_color "\033[0;90m" "c-u Delete entire line"
Imagine you want to go up 2 lines to edit a HN comment. You could move your right hand to arrow key, or you can simply press caps with your pinky and type "p" with your other pinky. So much faster! Now you can see why these are so effective, and are really my favorite.
Note that as you start to use these you will be pleased to see they apply in a lot of applications. For example, type command+L in chrome to jump to the address bar and highlight it, now type "news" in the address bar. The autocomplete dropdown will pop up. Now type control+n (readline move down) and you can scroll through the list.
I'm obsessed with optimizations and efficiency and the 2 things mentioned above are the absolute gems. Also, I highly recommend: https://medium.com/vunamhung/set-a-blazingly-fast-keyboard-repeat-rate-3d122ddac536 https://medium.com/vunamhung/set-a-blazingly-fast-keyboard-r...
`0` is a little to fast for me so I prefer speed `1` and it's perfect.
- rattray 6y agoDitto – I use some of these daily (mostly c-a, c-e, c-k) and didn't even know about others on your list. The shell reminder is a neat idea too; thanks for sharing that!
- pkrznaric 6y agoI'm sorry if this is a dumb question, but how do I actually use these? Control + A?
- deleted 6y ago[deleted]
- rattray 6y agoNot dumb, "c-" is ambiguous, but yes – it refers to the control key, so ctrl-a will get you back to the start of the line/sentence/etc.
- pkrznaric 6y agoMy ctrl key seems to mimic my Command key for most of these command and not do anything in other cases (Firefox & Word). Is there some setting I need to change?
- coldtea 6y agoThe shortcuts are meant for applications using readline or readline conventions (so tons of command line apps, but also lots of Cocoa apps). Firefox and Word probably are not in that category (don't know, I use Chrome/Safari and Pages).
- dhosek 6y agoNeither of those programs use readline. I map ctrl-e to end of line in Word because I use it so habitually. Safari uses these shortcuts as does terminal.
- waterhouse 6y agoI'm using these keybindings in Firefox right now, without any custom config (other than mapping caps lock -> control). Go to the URL bar and hit control-a and control-e; do they work? Type a few words of a reply comment, and in the comment text field, try control-a and control-e; do they work?
- heavyavocado 6y agoThis sounds really valuable but I have no idea what you're saying. What's "readline" keys? What's MOTD?
- chin7an 6y agoMOTD - message of the day, it's the small text blurb that's printed when you start a new shell instance on linux or mac computers. Not sure if it's a thing on windows. Readline refers to the GNU readline library [1] 1 - https://en.wikipedia.org/wiki/GNU_Readline https://en.wikipedia.org/wiki/GNU_Readline
- heavyavocado 6y agoAh thank you!
- coldtea 6y agoWhich (readline, that is) is used in tons of command line programs, shells, REPLs, etc. to parse user input. So if you know the shortcuts you can apply them in tons of programs...
- deleted 6y ago[deleted]
- 019341097 6y agoIf you don't use MOTD, putting the shortcuts you wanna memorize in a macOS sticky note works great. Or editing them into your desktop image. Or a legit paper sticky note / label printer label stuck to your monitor - no screen real estate gets consumed that way
- copperx 6y agoIf you love the Readline bindings, you should upgrade to Emacs! You're halfway there.
- yodsanklai 6y agoBecause there is no right ctrl on a mac keyboard, some of these shortcuts are inconvenient. For instance, ctrl-A. Do you use your pinky or your thumb?
- self 6y agoYou remap the caps lock key to control (System Preferences, Keyboard, Modifier Keys).
- wikyd 6y agoI've remapped my caps lock key to act as ctrl and it makes using these shortcuts much easier.
- sidsidsidsid 6y agoYeah it's annoying. Because I make lots of use of control, I usually map Right Command to Right Control, so I can easily thumb control, command or option at practically any time.
- nhlx2 6y agoEnter Karabiner-Elements, to bind right Alt to Control etc. It's one of the first pieces of software I install on a new Mac.
- mark-wagner 6y agoNot only that, if you hate the virtual escape key KE can make caps lock send escape if tapped and control if held. See https://medium.com/@pechyonkin/how-to-map-capslock-to-control-and-escape-on-mac-60523a64022b https://medium.com/@pechyonkin/how-to-map-capslock-to-contro...
- Exuma 6y agoI edited my post. You absolutely must rebind caps to control. One of the best changes I ever made, and I regret that I didn't add that to my post after so many people have seen it. Thanks for reminding me
- weaksauce 6y ago
- behnamoh 6y agoThey don't work in MS Word.
- Rebelgecko 6y agoControl-t to transpose also doesn't work in Firefox.
- vondur 6y agoMicrosoft has implemented their own text controls system in their apps. It's annoying as heck to me. I should say it's not true in Teams and OneNote. I'm guessing they are electron apps.
- dnhz 6y agoTools > customize keyboard. Select the All Commands category to see all possible shortcuts. You can adjust some shortcuts to match readline shortcuts. C-n, p, f, b, k, a, and e are all possible. Even Cmd-f and Cmd-b for forward word and backward word can be done. Some of these do override existing shortcuts. Also, this can’t be done for PowerPoint.
- copperx 6y agoIt's just easier to edit in Emacs and copy and paste into Word.
- caycep 6y agoI wonder if they were part of the original set of shortcuts or is this an inheritance/legacy of OS X's UNIX roots?
- imwally 6y agoI’ve read somewhere that they’ve been there since the NeXT days.
- ttepasse 6y agoThe Cocoa Text (Input) System maps shortcuts on Cocoa method selectors via a plist, so it makes sense that it originated at NeXT. https://www.hcs.harvard.edu/~jrus/site/cocoa-text.html https://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
- Someone 6y agoThey weren’t part of the original set of Mac shortcuts, and couldn’t have been. The keyboard of the first Mac didn’t have cursor keys, nor did it have a control key (https://en.m.wikipedia.org/wiki/Apple_Keyboard#Macintosh_Keyboard_(M0110) https://en.m.wikipedia.org/wiki/Apple_Keyboard#Macintosh_Key... ). Cursor keys came with the numeric keypad; IIRC, control keys debuted with “Saratoga”, the extended keyboard in 1987 (https://en.m.wikipedia.org/wiki/Apple_Keyboard#Apple_Extended_Keyboard_(M0115) https://en.m.wikipedia.org/wiki/Apple_Keyboard#Apple_Extende... )
- captainhat 6y ago"c-u" only works in the terminal.
- Exuma 6y agoTrue, but c-k also works and so does, c-a, so with c-a, c-k you can get the same effect with not too much more effort.
- Hackbraten 6y agoNot really because unlike c-u, the c-a c-k combo deletes the whole line, while I actually wanted to delete only the rest of the line. My workaround is ⇧⌘→ followed by Backspace but that always feels a little awkward to me.
- Exuma 6y agoYou might be confusing c-u with c-k? c-u deletes the entire line regardless of where the cursor is (in terminal). outside of terminal, c-a goes to beginning of line, and c-k deletes from the current cursor to the end of the line. Perhaps you should try c-k instead of ⇧⌘→.
- Hackbraten 6y agoYou’re right, I confused it but my point still stands. What I really meant to say: Not really because unlike c-u, the c-a c-k combo deletes the whole line, while I actually wanted to delete only the part of the line up to the cursor. My workaround is ⇧⌘← followed by Backspace but that always feels a little awkward to me.
- Exuma 6y agoAhhh yes, in that case I don't think there's a readline hotkey for that. However what I do is just command+backspace (no shift)
- vondur 6y agoWhy the remapping of the ctrl key?
- bigdict 6y agowhat the hell, ctrl-n/p works in Safari too… thank you so much!
- waterhouse 6y agoAs someone who uses the above constantly in Mac OS, including while typing this comment: Is there a way to make this happen in Linux—to have all those commands work in (the majority of) text fields across all applications, and to have Linux's original meaning of "c-a" (Select All) and so forth be accessible via "(Windows key)-a"?
- stevewodil 6y agoCreate keyboard shortcuts that map to the different arrow keys
- TrisMcC 6y agoFor GTK/Gnome you can enable Emacs input. For in gnome-tweak-tool it is under "Keyboard & Mouse".
- billti 6y ago> ... other than learning vim. Note you can also set your command-line editing key to vi[m] also with "set -o vi". See https://unix.stackexchange.com/questions/30454/advantages-of-using-set-o-vi https://unix.stackexchange.com/questions/30454/advantages-of...
- Gaelan 6y agoUnfortunately, macOS supports "readline-style" bindings everywhere, but there's no way to switch that into vim mode.
- andrei_says_ 6y agoAre there keys for jump to next or prevent word?
- Exuma 6y agoYou can only jump by word, forwards and back, by holding the option key while using the arrow left and right. Backspacing however can be done by word by using c-w to delete back by word. Unfortunately this hotkey only works in terminal I think, so you'd have to do option+backspace in chrome, etc.
- andrei_says_ 6y agoI don’t think option arrows work in terminal. I’m only able to go to beginning or end of line and with long lines that’s not ideal. Iterm2, built in Terminal, bash shell.
- Exuma 6y agoAh i see, interestingly I don't ever write "text" or sentences in iterm so I dont usually have to delete by word or even skip by word. But this may help: https://medium.com/@jonnyhaynes/jump-forwards-backwards-and-delete-a-word-in-iterm2-on-mac-os-43821511f0a https://medium.com/@jonnyhaynes/jump-forwards-backwards-and-...