1. 26
  1.  

  2. 4

    Ever typed anything like this?

    $ grp somestring somefile
    -bash: grp: command not found
    

    Sigh. Hit ‘up’, ‘left’ until at the ‘p’ and type ‘e’ and return.

    Yeah, but I finnd using “up” “Ctrl-a” “Ctrl-d” “grep” easier, especially as an emacs user.

    Generally speaking that would say that’s the biggest “hidden” feature of bash: emacs bindings by default. And that’s not only limited to movement commands like C-a, C-e, C-p, M-b, etc. You can kill lines or words with C-k or M-d, and yank them back in when needed with C-y. There’s even an “infinite kill-king” (by far the coolest name for a editor feature), to replace the last yanked section with the next item in the kill-ring. Of course, not everything is implemented, so theres no hidden mail client or M-x butterfly, but if you already are used to the default emacs editor binding, you get used to this quickly. And afaik, all tools that require GNU readline can do this. I just tested it out with Python, and it seemed to work.

    I also recall reading something about vi-bindings in the bash manpage, but I can’t testify on how useful harmful, annoying or useless they are.

    1. 6

      Emacs bindings by default is also one of the biggest hidden features of MacOS: the bindings work in all GUI text fields.

      1. 1

        Wow, I learned something new today. Prompted by your comment, I found this table comparing emacs bindings, OSX’s version of emacs bindings, and the more traditional Mac-style bindings for various operations.

        Looks like emacs’s M- bindings are mapped to ctrl-opt- on MacOS, which isn’t super convenient (e.g. I don’t see myself getting in the habit of using ctrl-opt-f over opt-rightarrow to move forward a word), but most of the C- bindings are convenient enough.

        1. 1

          I just discovered this a few days ago by accident because I have it set in GTK so I can use the bindings in my browser. I had to use a colleague’s (who is on macOS) browser and I just used them without thinking and only later realised ‘hey, wait a minute, why did that work?’.

          1. 1

            This is a major reason why I stay on OS X. I’m pretty sure I could reconfigure some Linux to get most of this, but probably not all of the niceness of text fields

            Would love to be proven wrong though

            1. 3

              I haven’t used GNOME for a while now, but I remember there being an option somewhere to used emacs keybindigs. And as it seems, all you need nowadays is to install the GNOME tweak tools, to activate it.

              (Alternatively, just use Emacs as your OS, heard they’ve got good support for emacs keybindings)

              1. 2

                Just FYI: That page is outdated, being written for 2.x era Gnome. Now the Emacs Input toggle is under the Keyboard & Mouse section.

          2. 3

            Yeah, won’t disagree. Occasionally, I find myself reaching for the caret because it comes to mind first.

            I’m an avid vi user, but the vi bindings on the command line never take for me. I always go back to the emacs ones.

            1. 3

              I use vi vindings and love them! I also never use ^ because I prefer interactive editing.

              It’s really nice that they work in Python and R as well as bash (because Python and R both use readline).

              In fact I think a large part of the reason that my OCaml usage trailed off is that the REPL utop doesn’t support readline. It only has emacs bindings!

              For those who don’t know, here is the beginning of my .inputrc:

              $ cat ~/.inputrc 
              set editing-mode vi
              
              set bell-style visible    # no beep
              
              1. 2

                Deleting words with C-w is also very helpful ime.

                1. 1

                  I use fc for that. Opens your $EDITOR with the last command in a file, the edited command will be run

                2. 3

                  Some of these are neat, but I don’t see myself going back to bash any time soon. After using fish for a few years, I think it’d be difficult for me to go back.

                  1. 3

                    Throwing it out there, but one of the best thing I learned about bash was ‘set -o vi’

                    1. 1

                      Sort of odd to describe using trap for cleanup but not mention trap ... EXIT.