set -o vi
Then you have vi keys in your shell. And it is marvelous.
set -o vi
Then you have vi keys in your shell. And it is marvelous.
Instead of that, create the following file:
~/.inputrc (tilde slash dot-inputrc)
And in that file put at least this:
set editing-mode vi
Now every program that you run that a) has its own command line, and b) uses the readline library (there are a lot) has vi commandline editing. psql, mysql, telnet, lftp, and many more.
man bash has a section on READLINE. For example, in man bash search for
editing-mode
which goes against his childish comment on emacs:
> Learn Vim (vi). There's really no competition for random Linux editing (even if you use Emacs, a big IDE, or a modern hipster editor most of the time).
Also, for more readline maneuvers: http://unix.stackexchange.com/questions/21788/how-to-delete-...
The way to think about it is that the prompt starts out in `vi insert mode` so whatever we type in will just be inserted at the prompt. However, we can hit the`Escape` key and move into `vi normal mode` where the keys are interpreted as normal `vi` commands. So, for example, once we hit `esc` we can navigate around the line using `h` and `l` and navigate history (previous lines) using `k` and `j`.
Commands I find very useful are:
`jk` : for history navigation
`bw`: for moving in the current line. These are word movement commands that are faster to navigate with.
`cw` : similarly, changing a particular word in the current line is also great. This works particularly well with history - retrieve a previous command and change a word or option
`dw` : for deleting the current word
`/` : is a fantastic command for searching history. `/cd` will bring up our last change directory command and just hitting `n` will cycle through all our change directory commands that are in history.
`AI` : to insert at the beginning/end of line
...and so on. If you have `vi` muscle memory it's a fantastic option for working on the shell.
(edit: Formatting)
v : to open command in a vi window. This is helpful for editing multi-line scripts/iterative composition.