Reputation: 8587
I want to set vi in editing mode in zsh (I am using oh-my-zsh) at start automatically when I open my shell, so at the beginning of my .zshrc
I have tried the following code:
set -o vi
or
bindkey -v
but when pressing enter in the shell I cannot enter the vi mode.
If I tried one of the two commands in the shell, it works.
Basically I want zsh to start in vi edit mode.
Any ideas how to solve this problem?
Upvotes: 63
Views: 101641
Reputation: 927
If you don't mind using a plugin for vi mode in zsh, here is a better choice for you, which I wrote, to quickly reach it.
zsh-vi-mode: A better and friendly vi(vim) mode plugin for ZSH.
After adding this plugin, then you can input with vi-mode like this:
Upvotes: 14
Reputation: 27698
bindkey -v
is enough to enable vi mode in ZSH. If you are worried the setting will be overwritten by another plugin, put the setting at the bottom of your ~/.zshrc
.
After vi mode is enabled, you enter the "insert" mode by default. To enter "normal" mode, use Esc. And i or a to switch back to "insert" mode.
BTW, softmoth/zsh-vim-mode is the most powerful vim mode plugin I've ever used in ZSH.
Using bindkey -v
may take over functionality such as history search with control+R and control+S. To restore that particular behavior, add the following lines after bindkey -v
:
bindkey ^R history-incremental-search-backward
bindkey ^S history-incremental-search-forward
Other bindings can be found in the ZSH manual Standard Widgets section.
Upvotes: 82
Reputation: 4857
If you are using https://ohmyz.sh/ you can add vi-mode
to the list of plugins in ~/.zshrc:
plugins=(git vi-mode)
Upvotes: 42