set -o vi#

You can use vim keybindings in Bash to edit commands.

Configuration#

Add the following to your ~/.bashrc file:

set -o vi

Motivation#

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) and f, F, t, T (character search).
  • History Search: In Normal mode, press / to search your command history.
    • eg. Typing /^kubectl finds recent kubectl commands. Use n and N to navigate results.
  • Open in Editor (v): Pressing v in 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); use f, t, etc., instead.