I'm getting used to vim bindings (like pressing w to go to word, dw to delete a word, and such) and it's modes (insert, normal, visual), and, out of curiosity would like to know: is there some kind of implementation of this behaviour of modes and bindings from vim to my terminal?
Have insert mode, normal mode and such...
1 Answer 1
It has insert and normal modes (the insert mode is default, and escape for normal mode).
When in vi normal mode, you can launch the full $EDITOR to edit the current line with v
(the same can be achieved when bash is in emacs mode with C-x C-e
).
In bash: set -o vi
You can run it at the command line for just this session or add it to your .bashrc file.
Many programs use readline
for input, and you can make any of them use vi-style keybindings by setting up your .inputrc
with
set editing-mode vi
set keymap vi
In zsh, if you change your EDITOR
environment variable, the shell will match it.
-
2@Somebody: Not
.vimrc
since you're still using the shell's built-in editor, but you can configure key bindings in.inputrc
for all readline applications (such as bash), in.bashrc
for bash specifically, in.zshrc
for zsh.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2010年12月15日 18:34:52 +00:00Commented Dec 15, 2010 at 18:34 -
3Note that on OS X, you'll need to put the
put -o vi
in ~/.bash_profile instead of ~/.bashrc .Steve Jorgensen– Steve Jorgensen2011年03月23日 07:24:15 +00:00Commented Mar 23, 2011 at 7:24 -
9I notice that the cursor appearance doesn't change in the different modes bash w/ vi key bindings. Is there any way to make it do that? It would be nice to have a visual indication of what mode I'm in.Steve Jorgensen– Steve Jorgensen2011年03月23日 07:27:31 +00:00Commented Mar 23, 2011 at 7:27
-
4For a visual indicator you can put
set show-mode-in-prompt on
,set vi-ins-mode-string "+"
andset-cmd-mode-string ":"
in your.inputrc
file.Will– Will2017年12月28日 04:43:11 +00:00Commented Dec 28, 2017 at 4:43 -
4@Will That worked, with a few changes. Namely, I added:
set show-mode-in-prompt on
set vi-ins-mode-string "+"
set vi-cmd-mode-string ":"
soap– soap2019年12月30日 15:22:59 +00:00Commented Dec 30, 2019 at 15:22