Skip to content

fix(cli): prevent unmapped keys in Vim Normal mode from inserting text - #22014

Closed
Rajeshpatel07 wants to merge 2 commits into
google-gemini:mainfrom
Rajeshpatel07:issue-21686/vim-normal-mode-keys
Closed

fix(cli): prevent unmapped keys in Vim Normal mode from inserting text #22014
Rajeshpatel07 wants to merge 2 commits into
google-gemini:mainfrom
Rajeshpatel07:issue-21686/vim-normal-mode-keys

Conversation

@Rajeshpatel07

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where pressing unmapped keys in Vim Normal mode would insert characters into input buffer. This change ensures that unhandled keys are ignored, aligning the CLI's behavior with standard Vim mechanics where text is only inserted during Insert mode.

Details

In the Vim hook, unmapped keys in NORMAL mode were inserted into the buffer. This fix intercepts those unmapped keys and prevents them from modifying the input. I have added tests cases to ensure unmapped keys are ignored and don't change the input buffer.

Related Issues

Fixes #21686

How to Validate

  1. Launch gemini-cli locally.
  2. Enable Vim Mode
  3. Enter Vim NORMAL mode by pressing Esc.
  4. Type unmapped keys such as H, M, Q, m, [ or /.
  5. Expected Result: The keys are ignored and do not appear in the text prompt.
  6. Enter INSERT mode by pressing i or a and verify that typing works normally.
  7. Run the tests npm run test to verify the new Vim normal mode tests pass successfully.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Rajeshpatel07
Rajeshpatel07 requested a review from a team as a code owner March 11, 2026 13:14
@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 11, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@Rajeshpatel07

Copy link
Copy Markdown
Contributor Author

/gemini summary

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request addresses an unexpected behavior in the CLI's Vim mode where pressing certain keys in Normal mode would inadvertently modify the input. The change ensures a more consistent and standard Vim experience by preventing unmapped keys from having any effect, thereby improving the robustness and user experience of the Vim integration.

Highlights

  • Vim Normal Mode Behavior: Fixed a bug where unmapped keys in Vim Normal mode would incorrectly insert characters into the input buffer.
  • Key Handling: Ensured that unhandled keys in Normal mode are now ignored, aligning the CLI's Vim behavior with standard Vim mechanics.
  • Test Coverage: Added new test cases to validate that unmapped keys are correctly ignored and do not modify the input buffer.
Changelog
  • packages/cli/src/ui/hooks/vim.test.tsx
    • Added a new test suite to verify that unmapped keys in Vim Normal mode are correctly swallowed and do not cause any buffer modifications or mode changes.
    • Included a comprehensive list of characters to test, ensuring broad coverage for various unmapped key scenarios.
  • packages/cli/src/ui/hooks/vim.ts
    • Introduced a conditional check within the handleInput function to explicitly ignore insertable keys when the Vim mode is NORMAL.
    • Modified the return value to true for ignored keys, indicating that the input was handled (swallowed) by the Vim hook.
Activity
  • A bot encountered an error while trying to create a summary.
  • The author manually requested a summary from the bot.

@gemini-cli gemini-cli Bot added the priority/p2 Important but can be addressed in a future release. label Mar 11, 2026
@Rajeshpatel07

Copy link
Copy Markdown
Contributor Author

hi @jacob314 , @gsquared94

please review this PR and let me know if any changes are required.

@Rajeshpatel07

Copy link
Copy Markdown
Contributor Author

Hi @SandyTao520

please review this PR and let me know if any changes are required.

@gemini-cli

gemini-cli Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@cocosheng-g

Copy link
Copy Markdown
Contributor

@Rajeshpatel07, apologies for the bot closing this PR! We tried to reopen it but couldn't (the branch might have been deleted). Please feel free to open a new PR with your changes if you'd still like to contribute. We will have someone review it shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing unmapped keys in Vim Normal mode inserts characters into input field

3 participants