Enabling vi keybindings on your favorite terminal
by mozammel
Most of the bash terminals have the emacs keybinding by default. But I’m a vi kind of guy and first thing I change on a terminal I’m working with is to change its default behavior handeling line editing to a vi style keybinding. You can easily accomplish this by typing in (for bash):
set -o vi
You can save this on your ~/.bashrc or ~/.profile (for mac) so that you don’t need to repeat it each time you fire the terminal.
When editing a line in the terminal, you can hit [ESC] and you will be in vi. Now you can use most of the vi commands to edit you current line. Some familiar commands are:
- b to go back one word
- 2b to go back two words
- w to go forward one word
- dw to delete a word after cursor
- dd to delete entire line
- d$ to delete from the current cursor position to the end of the line
- d0 to delete from the current cursor position to the beginning of the line
- cw to replace a word and go directly to insert mode, etc.