set -o vi#
You can use vim keybindings in Bash to edit commands.
Configuration#
Add the following to your ~/.bashrc file:
set -o viMotivation#
For vi users, leveraging editor muscle memory with commands like x, dB, w, and b is more intuitive than memorizing shell-native shortcuts like Ctrl+h, Ctrl+w, Alt+f, and Alt+b.
Key Features and Tips#
- Movement: Supports
w,W,b,B(words) andf,F,t,T(character search). - History Search: In Normal mode, press
/to search your command history.- eg. Typing
/^kubectlfinds recentkubectlcommands. UsenandNto navigate results.
- eg. Typing
- Open in Editor (
v): Pressingvin Normal mode opens the current command in the editor defined by<editor>(eg.vim). Saving and exiting (:wq) will execute the command immediately. This is extremely useful for complex multi-line or long commands.
Limitations#
- In-line search using
/is not supported (it is mapped to history search); usef,t, etc., instead.