๐Ÿ“– zsh-vi-man

March 2, 2026 ยท View on GitHub

๐Ÿ“– zsh-vi-man

Smart man page lookup for zsh vi mode (now with emacs mode support!)

Press K (vi normal mode), Ctrl-X k (emacs mode), or Ctrl-K (vi insert mode) on any command or option to instantly open its man page

License: MIT Zsh Tests


zsh-vi-man demo

โœจ Features

๐ŸŽฏ Smart Detection

Automatically finds the right man page for subcommands

git commit โ†’ man git-commit
docker run โ†’ man docker-run

๐Ÿ” Option Jumping

Opens man page directly at the option definition

grep -r    โ†’ jumps to -r entry
ls --color โ†’ jumps to --color entry

๐Ÿ”— Combined Options

Works with combined short options

rm -rf    โ†’ finds both -r and -f
tar -xvf  โ†’ finds -x, -v, -f

๐Ÿ“ Value Extraction

Handles options with values

--color=always     โ†’ searches --color
--output=file.txt  โ†’ searches --output

๐Ÿ”€ Complex Syntax Support

Detects correct command in pipelines, command substitutions & more

cat file | grep -i  โ†’ opens man grep
if true && ! [ -e   โ†’ opens man test at -e
printf "$(pwd; ls   โ†’ opens man ls

๐Ÿ› ๏ธ Multiple Formats

Supports various man page styles

GNU: -R, -r, --recursive
jq:  --slurp / -s:
find: -name, -type, -exec

๐Ÿ“ฆ Installation

zinit
zinit light TunaCuma/zsh-vi-man
antidote

Add to your .zsh_plugins.txt:

TunaCuma/zsh-vi-man
oh-my-zsh
git clone https://github.com/TunaCuma/zsh-vi-man \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-vi-man

Then add to your .zshrc:

plugins=(... zsh-vi-man)
Manual
git clone https://github.com/TunaCuma/zsh-vi-man ~/.zsh-vi-man
echo 'source ~/.zsh-vi-man/zsh-vi-man.plugin.zsh' >> ~/.zshrc

๐Ÿš€ Usage

Vi Normal Mode (Default)

  1. Type a command (e.g., ls -la or git commit --amend)
  2. Press Escape to enter vi normal mode
  3. Move cursor to any word
  4. Press K to open the man page

Emacs Mode / Vi Insert Mode

Without leaving insert mode or if using emacs mode:

  • Emacs mode: Press Ctrl-X then k
  • Vi insert mode: Press Ctrl-K

Examples

CommandCursor OnResult
ls -lalsOpens man ls
ls -la-laOpens man ls, jumps to -l
git commit --amendcommitOpens man git-commit
grep --color=auto--color=autoOpens man grep, jumps to --color
cat file | sort -r-rOpens man sort, jumps to -r
find . -name "*.txt"-nameOpens man find, jumps to -name

โš™๏ธ Configuration

Set these variables before sourcing the plugin:

# Vi normal mode key (default: K)
ZVM_MAN_KEY='?'

# Emacs mode key sequence (default: ^Xk, i.e., Ctrl-X k)
ZVM_MAN_KEY_EMACS='^X^K'  # Example: Ctrl-X Ctrl-K

# Vi insert mode key (default: ^K, i.e., Ctrl-K)
ZVM_MAN_KEY_INSERT='^H'   # Example: Ctrl-H

# Enable/disable emacs mode binding (default: true)
ZVM_MAN_ENABLE_EMACS=false

# Enable/disable vi insert mode binding (default: true)
ZVM_MAN_ENABLE_INSERT=false

# Use a different pager (default: less)
ZVM_MAN_PAGER='nvim'

Troubleshooting

Keybindings not working?

If keybindings don't work after sourcing the plugin, try running:

zvm_man_rebind

This can happen if:

  • Your plugin manager loads plugins before setting up keymaps
  • You call bindkey -e or bindkey -v after the plugin loads
  • Another plugin resets your keybindings

For persistent issues, add this to your .zshrc after sourcing the plugin:

# Ensure zsh-vi-man bindings are set
zvm_man_rebind
Key Binding Examples
Key NotationDescription
^KCtrl-K
^XkCtrl-X then k
^X^KCtrl-X then Ctrl-K
\ekAlt-k (or Escape then k)

For special keys, use zsh notation: ^[ for Escape, ^? for Backspace, etc.


๐Ÿ”Œ Integration with zsh-vi-mode

This plugin works seamlessly with zsh-vi-mode. It automatically detects zsh-vi-mode and hooks into its lazy keybindings system.

For best results, source this plugin after zsh-vi-mode:

source /path/to/zsh-vi-mode.zsh
source /path/to/zsh-vi-man.zsh

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

# Run tests
zsh test_patterns.zsh

# Test locally
source ./zsh-vi-man.plugin.zsh

๐Ÿ“„ License

MIT License - see LICENSE for details.


Made with โค๏ธ by Tuna Cuma