Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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-r...

`0` is a little to fast for me so I prefer speed `1` and it's perfect.



This sounds really valuable but I have no idea what you're saying. What's "readline" keys? What's MOTD?


MOTD - 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


Ah thank you!


Which (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...


If 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


If you love the Readline bindings, you should upgrade to Emacs! You're halfway there.


As 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"?


For GTK/Gnome you can enable Emacs input.

For in gnome-tweak-tool it is under "Keyboard & Mouse".


Create keyboard shortcuts that map to the different arrow keys


> ... 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...


Unfortunately, macOS supports "readline-style" bindings everywhere, but there's no way to switch that into vim mode.


I wonder if they were part of the original set of shortcuts or is this an inheritance/legacy of OS X's UNIX roots?


They 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_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_Extende... )


I’ve read somewhere that they’ve been there since the NeXT days.


The 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


Ditto – 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!


I'm sorry if this is a dumb question, but how do I actually use these? Control + A?


Not 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.


My 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?


I'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?


The 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).


Neither 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.


yes


Because 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?


I've remapped my caps lock key to act as ctrl and it makes using these shortcuts much easier.


Enter Karabiner-Elements, to bind right Alt to Control etc. It's one of the first pieces of software I install on a new Mac.


Not 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-contro...


The ergonomics are terrible, aren't they? I suppose in your case I'd probably use my pinky and suffer.

My Air has a JIS keyboard, so the control key is where your caps lock is. Most of my keyboards are configured this way (either physically or in software); on those that aren't, I use my opposing palm to press ctrl. I can't imagine using a Mac with flat keys and no right control =(


I just rebind caps lock to control and it's perfect. I haven't legitimately used caps lock in probably years.


I insist on keeping an old “full size” wired Mac keyboard around exactly to have a right-ctrl. I worry I’m slightly OCD about it.


I use karabiner elements to remap caps to ctrl for most chords, also it will act as escape if hit alone and it will act as the arrow keys when used with hjkl like in vim. and finally it will act as caps lock if you press it with right shift. pretty awesome setup.


I 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


Yeah 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.


You remap the caps lock key to control (System Preferences, Keyboard, Modifier Keys).


"c-u" only works in the terminal.


True, 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.


Not 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.


You 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 ⇧⌘→.


You’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.


Ahhh 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)


TIL!


No. C-u deletes between the beginning of the line and where the cursor is. In iterm at least.


I tested in both iTerm and Terminal and c-u for me deletes the entire line regardless of cursor... hmm


I can confirm that C-u has the behavior I described for me. Running Mojave. It's very useful at times in terminal as a sort of "reflected" C-k shortcut.

The way it behaves for me matches the description here: https://man7.org/linux/man-pages/man3/readline.3.html


Why the remapping of the ctrl key?


Because it allows you to type these hotkeys by moving your pinky 1 key to the left, which is orders of magnitude easier than the control key at the bottom left.


Never thought of that, good idea, now I have to give it a shot. Thanks!


what the hell, ctrl-n/p works in Safari too… thank you so much!


Are there keys for jump to next or prevent word?


You 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.


I 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.


Ah 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-...


They don't work in MS Word.


Tools > 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.


It's just easier to edit in Emacs and copy and paste into Word.


Microsoft 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.


Control-t to transpose also doesn't work in Firefox.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: