Skip to content

feat: zsh: vicmd counterparts for custom line expansions#21

Merged
bezhermoso merged 1 commit intomasterfrom
vicmd-expansions
Jan 13, 2026
Merged

feat: zsh: vicmd counterparts for custom line expansions#21
bezhermoso merged 1 commit intomasterfrom
vicmd-expansions

Conversation

@bezhermoso
Copy link
Copy Markdown
Owner

No description provided.

@claude
Copy link
Copy Markdown

claude bot commented Jan 13, 2026

Pull Request Review: Vi Command Mode Expansions

Summary

This PR adds vi command mode counterparts for all existing custom line expansions. The implementation mirrors the emacs mode bindings using x as a mnemonic prefix (matching ^X in emacs mode).


✅ Code Quality & Best Practices

Excellent work overall! The implementation demonstrates:

  1. Consistency: Each emacs mode binding now has a corresponding vi mode binding
  2. Clear documentation: The inline comments explain the rationale ("x" prefix is a mnemonic for "expansion")
  3. Proper organization: Vi mode bindings are grouped logically with their emacs counterparts
  4. Correct syntax: All bindings use appropriate zsh syntax

📋 Detailed Feedback

Strengths

  1. Smart keymap selection: Using -M vicmd correctly targets vi command mode only
  2. Appropriate mode transitions: Simple insertions correctly use the i prefix (e.g., 'igit add ') to enter insert mode before text insertion
  3. ZLE widget reuse: Correctly reuses existing widgets like _hotkey_git_commit, _hotkey_docker_exec, etc. instead of duplicating logic
  4. Comprehensive coverage: All command categories are covered:
    • Git shortcuts (lines 64-73)
    • Docker shortcuts (lines 82-85)
    • Common commands (lines 92-93)
    • Date insertion (lines 100-101)
    • Search patterns (lines 112-114)

Observations & Minor Considerations

  1. xdp binding (line 84): Uses 'idocker ps' without ^M, meaning it doesn't auto-execute (unlike the emacs version on line 77). This is intentional based on the pattern, but worth noting:

    • Emacs: bindkey -s '^Xdp' 'docker ps' (no auto-execute)
    • Vi: bindkey -M vicmd -s 'xdp' 'idocker ps' (no auto-execute)

    This is correct - consistency is maintained.

  2. Auto-execution commands: Both xgs (git status) and xgl (git log) correctly include ^M for auto-execution, matching emacs mode behavior.

  3. Cursor placement widgets: Date insertion (xdd) and search patterns (xfg, xrg) correctly bind to the existing ZLE widgets, which will work seamlessly in vi mode since they manipulate LBUFFER/RBUFFER directly.


🐛 Potential Issues

None identified. The code appears functionally correct.


⚡ Performance Considerations

No concerns. Key bindings have negligible performance impact. The implementation efficiently reuses existing widgets rather than creating duplicates.


🔒 Security Concerns

None. This is a personal dotfiles configuration with no security implications. All commands are:

  • User-initiated via explicit key combinations
  • Non-privileged operations
  • Shell expansion safe (no injection vectors)

🧪 Test Coverage

Manual testing recommended:

Since this is a shell configuration, automated testing is not typical. Consider manually verifying:

  1. Basic functionality: Test each binding in vi command mode

    # In your shell, enter vi command mode (ESC)
    # Then try: xga (should insert "git add " and enter insert mode)
  2. Edge cases to verify:

    • Widget bindings work correctly: xgc, xde, xdd, xfg, xrg
    • Auto-execution works: xgs, xgl
    • Insert mode prefix works: xga, xgp, xgP, xgd, xdc, xdp, xmk
  3. No conflicts: Ensure these bindings don't conflict with existing vi mode commands

    • x in vi mode normally deletes a character, but since these are multi-key sequences (xga, xgc, etc.), they shouldn't conflict
    • The prefix design is smart here!

Testing checklist (optional, for your use):

  • xgc opens git commit with cursor between quotes
  • xga enters insert mode and adds "git add "
  • xgs executes git status immediately
  • xde inserts docker exec with cursor positioned correctly
  • xdd inserts current date
  • xfg and xrg insert search commands with cursor placement

🎯 Overall Assessment

Approved! 🚀

This is a clean, well-implemented enhancement that brings feature parity between emacs and vi modes. The code:

  • Follows existing patterns consistently
  • Includes helpful documentation
  • Reuses existing widgets appropriately
  • Uses correct zsh syntax and conventions

The mnemonic x prefix is a clever design choice that mirrors the emacs ^X prefix while avoiding conflicts with standard vi commands.

Recommendation: ✅ Merge when ready


💡 Optional Future Enhancements

(Not required for this PR, just ideas for future consideration):

  1. Consider adding vi mode bindings for the commented-out shortcuts (Kubernetes, Python/venv, npm/yarn, systemctl) if you enable those in the future
  2. You might add a brief note at the top of the file mentioning that both emacs and vi modes are supported

Great work! 🎉

@bezhermoso bezhermoso merged commit 79fda15 into master Jan 13, 2026
1 check 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.

1 participant