You can configure your terminal to use Vi(m) keyboard shortcuts. This will work for the Bash shell and most command line applications including the Interactive Ruby Shell (irb), and MySQL’s command line client.
Here is how you get it to work:
- add ‘set -o vi’ to ~/.bashrc (if you use the Bash shell)
- add ‘bind -v’ to ~/.editrc
- add ‘set editing-mode vi’ to ~/.inputrc
You may need to create the above files if they don’t already exist.
You start in insert mode; as usual press ‘esc’ or ‘ctr-[‘ to enter command mode.
How it works
The line, ‘set -o vi,’ is invoking the Bash built-in command ‘set’. ‘set’ is used to configure Bash options. In this case, it is telling Bash to use the vi line editing interface. You can read the GNU Bash manual for more information. (Take a look at your shell’s documentation for vi keyboard configuration if you don’t use the Bash shell.)
The line, ‘bind -v,’ is used to configure the Command Line Editor library–see the ‘editline‘ and ‘editrc‘ man pages. It tells the library to bind all keys to the standard vi key bindings. This will configure applications that use the Command Line Editor library.
The last line, ‘set editing-mode vi,’ is used to configure the Readline library. It configures the library to use vi editing mode. Any applications compiled with Readline support will now use the vi key bindings. You can read more about the Readline init file here.
My company thanks you for the increased productivity!
Anyway to update the cursor to indicate which mode you are in?
That is a good question. I don’t think it is possible without patching the readline or editline libraries.
There is no way to do this with bash, but you can pull this off with zsh.
Check out the following link for more information: http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/
have fun.
Here’s a blog post I’ve written on changing the cursor color to indicate vi mode without using patches (for zsh).
http://andreasbwagner.tumblr.com/post/804629866/zsh-cursor-color-vi-mode
is there any way to get the .vimrc and plugins working in this mode?
No; as least I don’t think so. As I understand it the vi modes are a set of keybindings. You aren’t really running vi.
The Vi plugin for oh-my-zsh is pretty great (https://github.com/robbyrussell/oh-my-zsh/pull/154).
Thanks for your help! I am loving using the vim commands in my terminal.