News for hackers. Stuff that matters.
Re:Moving efficiently in the CLI by Exuma on Friday January 26, 2018 @05:17PM (#16243360)
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"
Re:Moving efficiently in the CLI by b5 on Friday January 26, 2018 @05:50PM (#16243543)

    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.

Re:Moving efficiently in the CLI by bmn__ on Friday January 26, 2018 @10:55PM (#16244770)
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...

Re:Moving efficiently in the CLI by emidln on Friday January 26, 2018 @06:11PM (#16243644)
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".
Re:Moving efficiently in the CLI by knight17 on Saturday January 27, 2018 @09:13AM (#16246269)
>>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

Re:Moving efficiently in the CLI by oxidized on Friday January 26, 2018 @07:09PM (#16243972)

  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.

Re:Moving efficiently in the CLI by zeptomu on Friday January 26, 2018 @10:22PM (#16244660)
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 `/`.
Re:Moving efficiently in the CLI by molteanu on Saturday January 27, 2018 @05:49AM (#16245713)
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.

Re:Moving efficiently in the CLI by azaras on Saturday January 27, 2018 @02:08PM (#16247553)
It is the BEST method.

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

Re:Moving efficiently in the CLI by xorcist on Saturday January 27, 2018 @02:48AM (#16245288)
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.
Re:Moving efficiently in the CLI by sedachv on Saturday January 27, 2018 @03:34AM (#16245381)
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.

Re:Moving efficiently in the CLI by sanbor on Saturday January 27, 2018 @08:14AM (#16246090)
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.

Re:Moving efficiently in the CLI by krylon on Friday January 26, 2018 @10:59PM (#16244780)
> 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.

Re:Moving efficiently in the CLI by equalunique on Saturday January 27, 2018 @04:29PM (#16248173)
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.
Re:Moving efficiently in the CLI by Exuma on Saturday January 27, 2018 @03:51PM (#16248027)
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.

Re:Moving efficiently in the CLI by eltoozero on Friday January 26, 2018 @06:58PM (#16243910)
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"
Re:Moving efficiently in the CLI by branchless on Friday January 26, 2018 @07:31PM (#16244068)
C-u deletes everything to the left of the cursor
Re:Moving efficiently in the CLI by pax on Saturday January 27, 2018 @03:43AM (#16245401)
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.

Re:Moving efficiently in the CLI by c256 on Saturday January 27, 2018 @07:04AM (#16245892)
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.

Re:Moving efficiently in the CLI by mkesper on Saturday January 27, 2018 @05:49AM (#16245715)
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.
Re:Moving efficiently in the CLI by coldtea on Saturday January 27, 2018 @10:51AM (#16246619)
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?

Re:Moving efficiently in the CLI by mjepronk on Saturday January 27, 2018 @05:48AM (#16245709)
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.
Re:Moving efficiently in the CLI by pax on Monday January 29, 2018 @10:32AM (#16258022)
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 :)
Re:Moving efficiently in the CLI by rmetzler on Saturday January 27, 2018 @03:25AM (#16245361)

    c-t  Swap chars (useful for correcting typos)
Re:Moving efficiently in the CLI by pbhjpbhj on Friday January 26, 2018 @05:48PM (#16243535)
Ctrl+W Delete word (and following spaces). [works in BASH at least]
Re:Moving efficiently in the CLI by baby on Saturday January 27, 2018 @06:06AM (#16245748)
Unfortunately a lot of these don't work anymore in Firefox in newer versions. No idea why. (alt-b for example)
Re:Moving efficiently in the CLI by frumiousirc on Saturday January 27, 2018 @11:14AM (#16246712)
In Firefox under Ubuntu/MATE with keyboard theme "emacs", most of these bindings are followed. Ctrl-W is taken up as "close tab".
Re:Moving efficiently in the CLI by StavrosK on Friday January 26, 2018 @06:55PM (#16243899)
This is great, does anyone have an equivalent for fish?
Re:Moving efficiently in the CLI by Exuma on Friday January 26, 2018 @08:40PM (#16244332)
One of the other replies to my comments appears to have converted it to Fish!
Re:Moving efficiently in the CLI by StavrosK on Saturday January 27, 2018 @07:42AM (#16245998)
Fantastic, thanks for the heads up!