Skip to content

feat: add neovim pager support and refactor into modular architecture#8

Merged
TunaCuma merged 4 commits intomainfrom
feat/neovim-support-and-refactor
Jan 4, 2026
Merged

feat: add neovim pager support and refactor into modular architecture#8
TunaCuma merged 4 commits intomainfrom
feat/neovim-support-and-refactor

Conversation

@TunaCuma
Copy link
Owner

@TunaCuma TunaCuma commented Jan 4, 2026

Summary

This PR adds neovim/vim as supported pagers and refactors the codebase into a modular architecture for easier extensibility.

Changes

Neovim Pager Support

  • Add neovim/vim as supported pagers using :Man command
  • Implement vim-compatible search patterns that match option definitions
  • Use nvim +"Man <cmd>" +only +/<pattern> format for proper integration
  • Fix terminal access issues with plugins like image.nvim

Modular Architecture

Refactored the monolithic zsh-vi-man.zsh into logical layers:

lib/
├── parser.zsh      # Word and command parsing (49 lines)
├── pattern.zsh     # Search pattern builders for less/nvim (93 lines)
├── pager.zsh       # Pager-specific logic (85 lines)
└── keybinding.zsh  # Keybinding management (50 lines)

Benefits:

  • Easy to add new pagers (add functions to lib/pager.zsh)
  • Easy to add shell environments (modify lib/keybinding.zsh)
  • Separate pattern logic for each pager type
  • Still lightweight (~340 total lines)

Testing

  • Added test_nvim.zsh with 46 comprehensive tests for neovim patterns
  • Updated CI workflow to run neovim tests
  • Updated Makefile with test-nvim target
  • All 101 tests pass (55 less + 46 nvim)

False Positive Prevention

  • Nvim patterns now only match options at line start (after whitespace)
  • Prevents matching options mentioned in description text like:
    • -f ...has no effect on the -d, -l, -R...
    • -@ ...in long (-l) output.

Testing Done

make test-all  # All tests pass

Manual testing with:

  • ls -la → finds -l, press n for -a
  • git commit -m → opens git-commit man page
  • tree | grep -r → opens grep man (not tree)

Fixes

Fixes #4

- Add neovim/vim as supported pagers with :Man command integration
- Refactor main file into modular lib/ structure:
  - lib/parser.zsh: word and command parsing
  - lib/pattern.zsh: search pattern builders for less/nvim
  - lib/pager.zsh: pager-specific man page opening logic
  - lib/keybinding.zsh: keybinding management
- Add comprehensive neovim pattern tests (test_nvim.zsh)
- Update CI workflow and Makefile with neovim tests
- Fix false positives in nvim search patterns
- Patterns now only match option definitions, not mentions in descriptions

Fixes #4
- Add dedicated zvm_open_vim() function for vim pager
- Load vim's bundled man.vim ftplugin before calling :Man
- Use </dev/tty to fix terminal access from zle widget
- Fixes 'E492: Not an editor command: Man' error
- Fixes terminal corruption and prompt indentation issues
The pattern "-.*[,/]" was too greedy, matching across entire description
lines when it should only match option definition lines.

Changes:
- Replace "-.*" with "-[^[:space:],/]*" to stop at spaces/commas/slashes
- Add "\(-[^[:space:],/]*[,/][[:space:]]*\)\+" to handle multiple
  preceding options like "-R, -r, --recursive"

This fixes the case where searching for "-l" would incorrectly match:
"     -f      ...this option has no effect on the -d, -l, -R..."

The pattern now correctly requires that options be in a proper option
definition format (comma/slash-separated list at line start) rather than
mentioned in description prose.
When MANPAGER is set to nvim but ZVM_MAN_PAGER is set to less,
calling man directly would invoke nvim through the system MANPAGER.
This breaks the shell when nvim is spawned from a zle widget without
proper terminal access.

Fix by setting MANPAGER=cat inline to neutralize the system pager,
then always pipe through ZVM_MAN_PAGER.
@TunaCuma TunaCuma merged commit 68b56f7 into main Jan 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How do I get it working with nvim man pages?

1 participant