set -o vi
Vi keys in the editor, Emacs on the CLI? This has never made any sense to me. set -o vi
Vi keys in the editor, Emacs on the CLI? This has never made any sense to me.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.
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.
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.
$ 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).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-forwardIt's never PostGRE.
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.
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.
set editing-mode viYou may try `rlwrap` which wraps programs without readline support.
But, there is something to be said for meeting people where they are. If folks know the emacs keybindings, let them 'control' away!
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.
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.)
I'm always confused by laptop designers who only include one ctrl key. How are we supposed to properly touch type modifiers otherwise?
Just stating the obvious: you’re not their target consumer.
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-...)
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 $ sudo -i
$ cd /va<tab> #results in "cd /var"
$ set -o vi
$ cd /va<tab> #results in: "cd /va "