No, all you need is a file called ~/.inputrc with at least the following contents:
set editing-mode vi
This causes any program that has its own command line (like bash, psql, etc) and uses the readline library (like bash, psql, etc) to have an editable command line with vi edit behavior.
In man bash, search for /^READLINE (READLINE at the beginning of a line).
Side note: if you want a nice TOC of bash or anything else, run this from the command line:
man -P cat bash |grep -E "^[^ ]"
Or if you're into the whole minimalism thing:
man -P "grep -E '^[^ ]'" bash
Or if you're into the whole reusability/automation thing:
The biggest issue[1] I've found with vi(m)-like modes in shells and readline is the lack of any feedback as to which mode you're in. That, and my tendency to use C-c as an alternative to esc in vim has...unfortunate consequences in the shell, although I could potentially rebind it.
[1] Actually, the biggest is 'discovered it set by default on a server you occasionally adminster, and taking far too long to realise why you're typing largely gibberish'
Thanks!
Yeah I have no idea!
I only just realised that ^H works because of a bash binding, while stty takes it from the erase key (which is rendered as '?').
Actually, that functionality is provided by the readline(3) library. If you understand how to configure it, you can make it usable in every interactive command you build, as long as it uses readline(3):
no, by default ctrl-r searches through your history based on subsequent keystrokes. although if you're good with it, it's just as fast as up/down arrows.
I think it's different. With these ones you can start typing a cmd, say 'dd ' and then hit up and it will got through all of the previous commands that started with 'dd '.
and have added a shortcut to iTerm to send escape-d when I hit alt-delete. It's like a softer version of ctrl-w, which I've found indispensable since I started using it. It's actually more consistent with the standard Mac alt-delete
C-r is reverse-search-history. You press C-r and start typing your search pattern to trigger an incremental search. Most recent command matching the pattern anywhere in the command is selected.
In contrast, history-search-backword requires you to start typing your pattern followed by the keystroke it was bound to. The most recent command that starts with your search pattern is selected.
Made a reddit thread to find .inputrc hacks or nice ideas. No success. I like having custom keybindings in the shell. But ultimately I will miss emacs when doing so.
I've increased my productivity recently by starting to use ctrl+p and ctrl+n for the previous and next command instead of the arrow keys, combined with ctrl+j for <enter> it has really made everything just a bit easier on the fingers.
I think it took me about 10 minutes to get used to it, it really is rather convenient. I still use <enter> very often when typing regular commands, but when I cycle through previous commands with ctrp+p/n it is much easier to hit ctrl+j.
Also, because my hands stay on the regular keys I don't have to look at my keyboard when switching betweeen typing commands and going through the history. It just feels more natural.
I've tried that a couple of times in the past but I just couldn't make it work for me. I guess it's vi instead of vim, so it felt really crippled in comparison. I seem to recall there was no normal / insert context either so you didn't know which mode you were in.
I'd be willing to try again if anyone had any good pointers for how to use it effectively though.
28 comments
[ 3.5 ms ] story [ 73.1 ms ] threadMaybe I should use ed first. BTW I recently came across a contractor that routinely used ed because 'I want to know what's going on!'
In man bash, search for /^READLINE (READLINE at the beginning of a line).
Side note: if you want a nice TOC of bash or anything else, run this from the command line:
Or if you're into the whole minimalism thing: Or if you're into the whole reusability/automation thing: And then[1] Actually, the biggest is 'discovered it set by default on a server you occasionally adminster, and taking far too long to realise why you're typing largely gibberish'
...can be replaced with `bind -P`.
Also, \e represents ESC; tab is represented by \t.
Have updated. Schoolboy error with tab/escape...
However, do you know why tab-tab works as complete?
http://www.gnu.org/software/bash/manual/html_node/Command-Li...
Since then, .inputrc has been an indispensable part of my dotfiles! This one alone saves so much headache:
In contrast, history-search-backword requires you to start typing your pattern followed by the keystroke it was bound to. The most recent command that starts with your search pattern is selected.
Also, because my hands stay on the regular keys I don't have to look at my keyboard when switching betweeen typing commands and going through the history. It just feels more natural.
I'd be willing to try again if anyone had any good pointers for how to use it effectively though.