Hacker News new | past | comments | ask | show | jobs | submit login

Here's a few more that the diagram is missing, along with a function I created that inserts these commands (in dark gray so it's not intrusive) every time I start ZSH shell, like flash cards.

Keep in mind, most of these work anywhere in OS X, not just in the terminal.

Put this in your .bashrc or .zshrc

    # 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"



    Keep in mind, most of these work anywhere in OS X,
    not just in the terminal.
That's one of my absolute favourite things about Mac OS -- because Cmd exists, and takes over what Ctrl is used for on Windows and Linux, I can use these Ctrl commands and they work as I expect.

I wonder if it's possible to get Linux to work the way the Mac does in this regard? Allocate a Meta key to do what Ctrl does move of the time, so that these Ctrl commands became available again? I'd really find it easier to use Linux if that was possible.


Yes, that works out of the box with every KDE application. I recommend Super as modifier key rather than Meta because most keyboards on the market have a physical Super key or two.

https://encrypted.google.com/search?tbm=isch&q=kde+rebind+ke...


Gnome/GTK and KDE both have keybinding themes that can be set to emacs. You can do it for GNOME/GTK from gnome-tweak tool. Otherwise you can use gsettings or edit the config directly. Just google "emacs gnome keybindings".


>>That's one of my absolute favourite things about Mac OS

Mine too, but I'm on Windows where none of this work out of the box. However, I've found XKeymacs [0] which allows Emacs keys system wide. It is not fool proof, but I've found that the movement keys can be used without much trouble.

Currently I use:

Movement:

C-b C-f backward/forward-char

M-b M-f backward/forward-word

C-p C-n previous/next-line

C-a C-e Home End

C-x h

Capitalisation:

M-l M-c downcase-word, capitalise-word

M-F12 rollup-window

C-z iconify-deiconify-frame

C-q enable-disable xkeymacs

[0] https://github.com/fujieda/xkeymacs http://xkeymacs.osdn.jp/

I also use TouchCursor [1] to get vim like hjkl movement system wide while Space is pressed

[1] https://martin-stone.github.io/touchcursor/overview.html


  Keep in mind, most of these work anywhere in OS X, not just in the terminal.
Adding on to this - this works in many places in OS X, since many programs happen use NSTextField, which can have shortcuts configured at the OS level.

You can further customize the shortcuts available in a file called DefaultKeyBinding.dict

I use a very slightly modified version of this: https://gist.github.com/cheapRoc/9670905

I highly recommend looking into that, for anyone who is familiar with emacs keybindings and would like them everywhere.


Nice idea and important quick-movements.

However as a Vim user (mostly motivated by the fact that I can move around pressing single keys which I find more "wrist-ergonomic" - potential fast navigation is a nice plus), I always wonder how heavy emacs users deal with CTRL-acrobatics and movement - do you use c-f/c-b for going forward/backward or the usual cursor keys?

For vi users it makes sense to set $readline (~/.inputrc) to vi-style, so for completion here the vi-style bindings (although probably obvious if you used to Vim).

  l "Move forward"
  h "Move backward"
  k "Move up" (step history backward)
  j "Move down" (step history forward)
  ^ "Jump to beginning of line"
  $ "Jump to end of line"
Deleting works as usual with `d` combinations. Furthermore it is convenient to search the history via `/`.


Honestly, I press both ctrl keys with my palms: http://ergoemacs.org/emacs/swap_CapsLock_Ctrl.html

I'm hearing people say that "that's impossible" or "it's weird", but I've used this method for ~2 years now. It has become muscle memory.


It is the BEST method.

I put a little pad over the Ctrl Keys to press it easily with muy palm.


Ctrl-heavy programs are much easier to use when you map the Ctrl key back to its original position, leaving the Ctrl-labeled key for whatever Hyper needs you have.


Yes, the Lisp Machine keyboard layout: https://deskthority.net/wiki/Symbolics_layout

That way you can press Control or Alt/Meta (or both at the same time) with the thumb of either hand without a lot of movement. C-f and C-b can be done with either left hand only, or left hand for f/b and right thumb on Control (what used to be Alt, on PC keyboards). Rebinding Caps Lock to Backspace also saves a lot of hand movement. Only a handful of small changes and you get a much better keyboard layout.


Is it just me or it looks crazy that the Space Cadet keyboard has thumbs up and down? https://deskthority.net/wiki/File:Space-cadet_guts.jpg

Looking at the keys below maybe it was for up/down.


> do you use c-f/c-b for going forward/backward or the usual cursor keys?

I do. With emacs, you usually have a finger near the Ctrl key at all times anyway, so hitting f or b is much more convenient than moving my right hand over to the arrow keys.


I love these shortcuts in Vim, but now that I primarily type in Dvorak, I have since reprogrammed my keyboard to have the home, end, and arrow cluster directly beneath my fingers on the home row. Just need to activate a function layer with my thumb in order to access those keys. The keyboard I use is called an Atreus.


You absolutely have to remap the caps-lock key to your control key... it's so vital. It unlocks a whole paradise of hotkeys that are easily accessible.

I meant to include it in my original post but I can't edit it now.


Here's a version for fish, goes in ~/.config/fish/config.fish

  # MOTD
    function echo_color
      printf "\033[0;90m$argv[1]\033[0m\n"
    end
    echo_color "c-f  Move forward"
    echo_color "c-b  Move backward"
    echo_color "c-p  Move up"
    echo_color "c-n  Move down"
    echo_color "c-a  Jump to beginning of line"
    echo_color "c-e  Jump to end of line"
    echo_color "c-d  Delete forward"
    echo_color "c-h  Delete backward"
    echo_color "c-k  Delete forward to end of line"
    echo_color "c-u  Delete entire line"
And a slightly optimized bash version (YMMV):

  # MOTD
    function echo_color() {
      printf "\033[0;90m$1\033[0m\n"
    }
    echo_color "c-f  Move forward"
    echo_color "c-b  Move backward"
    echo_color "c-p  Move up"
    echo_color "c-n  Move down"
    echo_color "c-a  Jump to beginning of line"
    echo_color "c-e  Jump to end of line"
    echo_color "c-d  Delete forward"
    echo_color "c-h  Delete backward"
    echo_color "c-k  Delete forward to end of line"
    echo_color "c-u  Delete entire line"


C-u deletes everything to the left of the cursor


Can someone explain the benefits of c+(f,b,p,n) instead of plain arrow keys?

Also, for c+h/d there's always a dedicated key/single stroke for at least one of those delete actions.


In addition to the control- versions, there are meta- and control+alt- versions that work the same way in greater logical units. For example, moving forward by 1 character/word/sentence-or-expression uses different modifiers for the same keybinding. In Emacs, these consistenly pervade the interface, so, for example, paragraphs in text modes are akin to blocks in or functions in programming modes (depending on if the language is block or function based). This is one reason that Emacs tends to swallow other user interfaces for dedicated Emacs users — everything is highly consistent, and you get a giant head-start on a new systems. Of course, it helps that Emacs is massively customizable, so when something doesn’t quite do what you want, it’s usually a very small bit of hacking to change that.

Historically, many of those keybindings date back to very crude remote terminals where control codes and tty modes were a real concern. For example, I’ve used systems (in the 90’s) where the delete key could freeze your remote connection. Emacs, because of it’s age and ubiquity, has grown up somewhat “around” those traps.


Your fingers stay near home row so you can type faster. Cursor keys are way to far off and differ very much between different keyboards.


What about any benefits of moving your hands around though?

Unless one is a court typist, where wpm matters fully, maybe moving a little and not keeping one's hands on the home row can help avoid carpal tunnel and RSI?


You can keep your hands in typing position on the keyboard while performing these operations. Using the arrow keys or backspace means you need to move to another part of the keyboard which interrupts your flow.


Point taken, thank you. Though, trying it out now, I realised f,b,p,n are not quite next to each other, and funnily enough, while I can easily type without looking at the keyboard, when I use a modifier key, the muscle memory used for typing doesn't seem to help as much, it seems it needs new training. Seems I need to flex more :)


    c-t  Swap chars (useful for correcting typos)


Ctrl+W Delete word (and following spaces). [works in BASH at least]


Unfortunately a lot of these don't work anymore in Firefox in newer versions. No idea why. (alt-b for example)


In Firefox under Ubuntu/MATE with keyboard theme "emacs", most of these bindings are followed. Ctrl-W is taken up as "close tab".


This is great, does anyone have an equivalent for fish?


One of the other replies to my comments appears to have converted it to Fish!


Fantastic, thanks for the heads up!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: