News for hackers. Stuff that matters.
Re:Moving efficiently in the CLI by itomato on Friday January 26, 2018 @04:27PM (#16243037)

    set -o vi
Vi keys in the editor, Emacs on the CLI? This has never made any sense to me.

https://popcon.debian.org/main/editors/by_inst

Re:Moving efficiently in the CLI by ggm on Friday January 26, 2018 @04:53PM (#16243187)
Its a historical artifact of how in-line edit emerged as a thing for most people. MIT had huge influence in the development of window systems (X10/X11) and adopted emacs string edit mode in most type in boxes. Bash came from a community which had a strong emacs usage. So, the default in both the window system and in the bash shell, was emacs, even if you use ed/ex/vi

Because most people used awk/grep/sed/ed/ex/vi the regex format tended that way. But enough people used tcsh or bash in emacs by default, that shell and omnibox (when browsers eventuated) edit defaulted to emacs.

Thats my theory: accidental happenstance and defaults.

Re:Moving efficiently in the CLI by SmirkingRevenge on Friday January 26, 2018 @06:06PM (#16243610)
And if I'm not mistaken, during that time, the ctrl key was typically where caps lock is today (maybe just on certain machines?) - and that is what influenced the frequent use of ctrl for key shortcuts in libraries lile readline.
Re:Moving efficiently in the CLI by hoosieree on Friday January 26, 2018 @08:41PM (#16244337)
Re:Moving efficiently in the CLI by ggm on Friday January 26, 2018 @08:18PM (#16244264)
may well be. not that escape is so far away from a pinkie, for the modal people (like me)
Re:Moving efficiently in the CLI by SmirkingRevenge on Friday January 26, 2018 @09:33PM (#16244520)
It pretty far away, compared to capslock. Especially on modern laptops.. lile touch bar macs that actually remove the the entirely
Re:Moving efficiently in the CLI by ggm on Saturday January 27, 2018 @06:25AM (#16245799)
Hateful. Annoying. Thank goodness for kbd remapping
Re:Moving efficiently in the CLI by okket on Friday January 26, 2018 @04:53PM (#16243194)
I am a fan of vi/vim, esp. as a remote shell editor. But the vi support in readline CLIs is overkill IMHO. I don't see the need for the 'extra power' of vi there, esp. the modes. A few well known keyboard short cuts are just fine for a CLI.

This also works the other way around: A few EMACS based shortcuts are the better 'lowest common denominator' than to force vi modes on everyone. Many are not willing to go down the vi/vim path, for various reasons.

Re:Moving efficiently in the CLI by imiric on Saturday January 27, 2018 @03:05AM (#16245318)
I disagree, and find the vi mode (and extended Vim bindings) very useful in the shell.

Consider a long cURL command split over several lines. If every option is on a separate line, removing one is a `dd` keystroke away. Adding a new option is also very efficient.

Extended Vim bindings will also allow you to delete everything within brackets/delimiters (e.g. `di"`) or delete everything up until a character, etc. These are all simple keystrokes that translate well to the shell.

You could also open the command in your $EDITOR anyway (bound to `V` for me), but I reserve that for really long and unwieldy commands.

Re:Moving efficiently in the CLI by jethro_tell on Friday January 26, 2018 @05:09PM (#16243297)
HOW DO YOU EXIT THIS SHELL??
Re:Moving efficiently in the CLI by okket on Friday January 26, 2018 @05:11PM (#16243311)
Re:Moving efficiently in the CLI by Groxx on Friday January 26, 2018 @05:28PM (#16243432)
ed(1) is the standard editor

https://twitter.com/ed1conf

Re:Moving efficiently in the CLI by zeptomu on Friday January 26, 2018 @10:33PM (#16244694)
After years of using Vim and Bash this was a relief that I learned way too late. For the lazy ones

  $ cat >~/.inputrc 
  set editing-mode vi
  set keymap vi

  $if mode=vi
    set keymap vi-insert
    "jj": vi-movement-mode
  $endif
Obviously you want to change vi-movement-mode to your favorite ESC style. E.g. searching through your last git commands becomes 'jj/git' then (you have to go to movement mode first, as insert mode is the default in the shell - which makes kind of sense).
Re:Moving efficiently in the CLI by mpblampo on Friday January 26, 2018 @04:47PM (#16243163)
Thank you for this! I had no idea this existed. It is perfect for vim users. Very happy that I can now jump around to my heart's content without learning a new set of keyboard shortcuts.
Re:Moving efficiently in the CLI by funkymike on Friday January 26, 2018 @05:27PM (#16243422)
Even better is to create a .inputrc configuration file. This is used by readline so it will affect your shell and some other utilities. You can do even more in there too.

For example I use this:

  set editing-mode vi

  # Up and down arrows keys search history based on what is already typed.
  "\e[A": history-search-backward
  "\e[B": history-search-forward
Re:Moving efficiently in the CLI by foobarrio on Friday January 26, 2018 @06:52PM (#16243883)
This is actually my preferred config. The reason being emacs shell buffers. I can interact with any shell tool using the full text editing features of emacs. I've had to interact with many Oracle databases via sqlplus. "sqlplus" is not a fun tool to use on the shell. However in emacs it is perfectly fine and works as well as the command line interfaces from PostGRE or MySQL. The inline shell also allows automatic history, block selecting and line truncate/wrapping controls across all tools. However for pure text editing, it's always vim for me. I've even found myself launching emacs+shell within tmux in one pane and vim in another.
Re:Moving efficiently in the CLI by mulmen on Friday January 26, 2018 @07:15PM (#16244003)
Sorry, unrelated nitpick but the name is PostgreSQL or Postgres. Postgres started in 1986 as a followup to Ingres and the name was meant to mean after-Ingres. The query language was later replaced with SQL and the name changed again to a portmanteau of Postgres SQL

It's never PostGRE.

https://www.postgresql.org/about/history/

Re:Moving efficiently in the CLI by totierne2 on Saturday January 27, 2018 @07:09AM (#16245910)
Have you tried sqlcl from Oracle? 20 meg download (requires java). Up down left right work. Use sql hr@ instead of sqlplus hr @ (I am one of the developers.) . I should try it from within Emacs.
Re:Moving efficiently in the CLI by zeveb on Friday January 26, 2018 @05:18PM (#16243367)

    emacs
Why not just use emacs everywhere? I suppose if you use spacemacs (which has vim keybindings) then you might want to 'set -o vi' on the command line.

Emacs has Org-mode & Magit, each of which should be reason enough to switch. Then there're notmuch, gnus, slack-mode, eww …

Seriously, emacs really is a more powerful environment[0]. Modern vim tries to be as flexible as emacs, but the language isn't as nice.

E.g. Damian Conway's[1] simple example:

    function! ToggleSyntax()
       if exists("g:syntax_on")
          syntax off
       else
          syntax enable
       endif
    endfunction
    
    nmap <silent>  ;s  :call ToggleSyntax()<CR>
would be:

    (defun toggle-syntax ()
      (syntax (not syntax))
    
    (global-set-key (kbd "M-C-s") toggle-syntax)
in a hypothetical elisp for a vim-like editor[2]. In his article he refers to vimscript a more humane than elisp, but I think this simple example shows he's wrong.

His next example is a command to capitalise a line, centre it, then move down:

    function! CapitalizeCenterAndMoveDown()
       s/\<./\u&/g   "Built-in substitution capitalizes each word
       center        "Built-in center command centers entire line
       +1            "Built-in relative motion (+1 line down)
    endfunction
    
    nmap <silent>  \C  :call CapitalizeCenterAndMoveDown()<CR>
I think this is a lot clearer:

    (defun capitalize-centre-and-move-down ()
      (interactive)
      (upcase-region (line-beginning-position) (line-end-position))
      (center-region (line-beginning-position) (line-end-position))
      (forward-line))
[0] https://sites.google.com/site/steveyegge2/effective-emacs

[1] https://www.ibm.com/developerworks/library/l-vim-script-1/in...

[2] For the real emacs, it's just font-lock-mode.

Re:Moving efficiently in the CLI by 0x445442 on Friday January 26, 2018 @10:11PM (#16244632)
I've used Emacs off and on for years now. But I can never get to that place where I get totally emersed because of the clunky terminal/shell story. I've tried eshell but what always gets me is having to C-c while in the terminal or eshell to get back to a different buffer.

I prefer M-x and fuzzy function entry to key bindings and when I'm in a terminal buffer or eshell I always go for M-x which won't work.

Any tips would be appreciated as I really like everything else about Emacs.

Re:Moving efficiently in the CLI by sedachv on Saturday January 27, 2018 @03:42AM (#16245398)
term and ansi-term bind the whole keyboard, but eshell and shell don't. Are you sure you are really running eshell?
Re:Moving efficiently in the CLI by hibbelig on Saturday January 27, 2018 @09:35AM (#16246345)
I used to have a command “vi” in eshell that basically ran find-file. It took some getting used to using Emacs keys after invoking a command vi, but it worked.
Re:Moving efficiently in the CLI by alan5 on Friday January 26, 2018 @05:44PM (#16243516)
If you modify your .inputrc with the following this should propagate to all of readline as well (e.g. python):

    set editing-mode vi
Re:Moving efficiently in the CLI by CDRdude on Friday January 26, 2018 @05:57PM (#16243565)
What shell does that work in? On a mac, I have that set in my .inputrc and it does not propagate to python.
Re:Moving efficiently in the CLI by zeptomu on Friday January 26, 2018 @10:44PM (#16244729)
Bash. Actually it depends if the program uses libreadline - which should be the case for Python's REPL?

You may try `rlwrap` which wraps programs without readline support.

Re:Moving efficiently in the CLI by mooreds on Friday January 26, 2018 @05:08PM (#16243295)
I came here to post that, glad you beat me to it. Reaching for that control key? Ouch. Though I guess when you use vi keybindings, you are occasionally reaching for the escape key.

But, there is something to be said for meeting people where they are. If folks know the emacs keybindings, let them 'control' away!

Re:Moving efficiently in the CLI by SmirkingRevenge on Friday January 26, 2018 @06:01PM (#16243586)
Remap that caps lock key that you never use to ctrl. Your life is changed. You are welcome :)
Re:Moving efficiently in the CLI by Lio on Friday January 26, 2018 @05:22PM (#16243396)
As a dyed in the wool Vi user. I still want ctrl where I can reach it easily.

Ctrl-[ for escape and when in Insert mode, ctrl-h backspace; ctrl-w delete word; ctrl-u delete line; Ctrl-m return; ctrl-i tab, etc.

Re:Moving efficiently in the CLI by sergeykish on Friday January 26, 2018 @07:02PM (#16243938)
I once swapped Ctrl and Alt and never looked back. It feels so natural and it happens to match Symbolics Space-Cadet Keyboards layout too http://xahlee.info/kbd/space-cadet_keyboard.html

Advised by http://xahlee.info/kbd/linux_swap_modifier_keys.html

    ! -*- coding: utf-8 -*-
    ! 2013-02-04 swap Alt and Ctrl http://xahlee.info/

    !  xmodmap -pke | egrep '(Control|Super|Alt|Menu)'
    ! keycode  37 = Control_L NoSymbol Control_L
    ! keycode  64 = Alt_L Meta_L Alt_L Meta_L
    ! keycode 105 = Control_R NoSymbol Control_R
    ! keycode 108 = Alt_R Meta_R Alt_R Meta_R
    ! keycode 133 = Super_L NoSymbol Super_L
    ! keycode 134 = Super_R NoSymbol Super_R
    ! keycode 135 = Menu NoSymbol Menu
    ! keycode 147 = XF86MenuKB NoSymbol XF86MenuKB
    ! keycode 204 = NoSymbol Alt_L NoSymbol Alt_L
    ! keycode 206 = NoSymbol Super_L NoSymbol Super_L

    clear control
    clear mod1
    keycode 37 = Alt_L Meta_L
    keycode 105 = Alt_R Meta_R
    keycode 64 = Control_L
    keycode 108 = Control_R
    add control = Control_L Control_R
    add mod1 = Alt_L Meta_L
Re:Moving efficiently in the CLI by SmirkingRevenge on Friday January 26, 2018 @06:13PM (#16243659)
Im a broken record in this thread right now... for goodness sake, remap capslock to ctrl!!
Re:Moving efficiently in the CLI by wyclif on Friday January 26, 2018 @06:51PM (#16243873)
That's the first thing I do when I start a new MBP.
Re:Moving efficiently in the CLI by Lio on Saturday January 27, 2018 @03:20AM (#16245344)
Yep, me too. The second thing I do is to remap the right alt key (used to be a numeric keypad 'enter' key back on my original MacBook Pro) to a second ctrl key.

I'm always confused by laptop designers who only include one ctrl key. How are we supposed to properly touch type modifiers otherwise?

Re:Moving efficiently in the CLI by henriquemaia on Saturday January 27, 2018 @04:05AM (#16245464)
> I'm always confused ...

Just stating the obvious: you’re not their target consumer.

Re:Moving efficiently in the CLI by Lio on Sunday January 28, 2018 @02:40AM (#16250304)
Maybe, there's probably some truth to that.

Apple do make it easy to remap the Alt key though and include a terminal and CLI commands by default so they must have some interest in business from people like me. ;)

(I would like to start a campaign to get the Mac Unix science page back again https://www.macobserver.com/tmo/article/apple-drops-science-...)

Re:Moving efficiently in the CLI by mooreds on Friday January 26, 2018 @05:39PM (#16243492)
different strokes for different folks. I did not know about those insert mode keystrokes. Thanks!
Re:Moving efficiently in the CLI by Lio on Saturday January 27, 2018 @03:15AM (#16245338)
Yeah, I have some problems with RSI in my right wrist (stop sniggering at the back).

I think it's mostly down to the way I twist to reach backspace rather than move my whole hand from the home row. Ctrl-h, Ctrl-w and Ctrl-m really help with that.

The only problem I have is that I don't know how to remap Ctr-m to return in X windows applications. I use Karabiner on a macOS and Gnome Tweak tool on Linux for the others.

It's somewhat frustrating to have different shortcuts in the terminal, where I spend most of my time and the browser where I spend most of the rest.

Edit: (If anyone can suggest a good way of mapping ctrl-m to return in Linux browsers I'd really appreciate it.)

Re:Moving efficiently in the CLI by SmirkingRevenge on Friday January 26, 2018 @06:10PM (#16243641)
Also ctrl-c does everything esc does in vim. When capslock is remapped to ctrl, its far easier and faster in most cases than reaching for esc.
Re:Moving efficiently in the CLI by zeptomu on Friday January 26, 2018 @10:46PM (#16244737)
Doesn't ctrl-c clear the whole line (maybe SIGINT related?) in vi-mode?
Re:Moving efficiently in the CLI by SmirkingRevenge on Saturday January 27, 2018 @12:08AM (#16244946)
Well, in vanilla vi - I'm not sure (quite frankly, anyone who stands by vanilla vi as a great way to edit text is fudging insane). In typical VIM installs, ctrl-c and esc are aliases of one another.
Re:Moving efficiently in the CLI by zeptomu on Saturday January 27, 2018 @12:36AM (#16245009)
Yeah, I meant vi(m)-mode in Bash/readline as mentioned in this discussion. When editing or correcting a command it may be inconvenient to destroy the whole line when switching to movement-mode (which does not happen, if it is not ctrl-c).
Re:Moving efficiently in the CLI by toyg on Friday January 26, 2018 @07:06PM (#16243954)
On the Japanese keyboard, Ctrl is where it should be: above Shift, replacing the useless and memetastic CapsLock.
Re:Moving efficiently in the CLI by u801e on Friday January 26, 2018 @07:03PM (#16243944)
You can always use ctrl-[ instead of esc.
Re:Moving efficiently in the CLI by DavideNL on Saturday January 27, 2018 @05:41AM (#16245689)
One thing that annoys me on macOS is that "set -o vi" stops tab completion from working when logging in as root.

  $ sudo -i
  $ cd /va<tab> #results in "cd /var"
  $ set -o vi
  $ cd /va<tab> #results in: "cd /va    "
Re:Moving efficiently in the CLI by debugxyz on Friday January 26, 2018 @09:22PM (#16244480)
Not enough people know about this config, bash/zsh compatible.