GramEditor/gram
38
985
Fork
You've already forked gram
88

Add Minimal base keymap for use with vim/helix keys #144

Merged
krig merged 3 commits from tjk/gram:vim-keymap into main 2026年03月21日 20:30:33 +01:00
Contributor
Copy link

Fixes #117

Hopefully the commit messages are mostly explanatory:

(first commit is just a fix for emacs being neglected)

 docs: correct base keymap to emacs and add missing emacs to list
 
 If you remove the base keymap from your user settings and restart, emacs
 will be selected, not VSCode.
 Add "minimal" base keymap
 
 This allows users to enable vim/helix keybinds without inheriting a full
 set of keybinds from another editor. It only includes a small set of
 bindings that are normally provided by another editor's binds and are
 missing from the vim/helix bindings, and that are not vim/helix-specific,
 meaning they don't care about editor mode and don't use vim/helix-style
 keyboard shortcuts. (Missing vim/helix-specific keys will be added to
 their bindings directly.)
 Add missing vim/helix keybindings for use with Minimal base
 
 Some basic editing functionality (enter for newline, backspace, etc.)
 was provided by other editors' keymaps, but if you use the Minimal base
 keymap, some basic functionality that depends on vim/helix modes or
 binding styles was still missing, and is provided here.

This result differs slightly from the discussion in #117 because of the need for some keys to check vim mode, which doesn't belong in a base keymap. Also, I named it "Minimal (for vim/helix)" in user-facing places because a general "Minimal" base keymap (that would also work for non-vim/helix users) would require a lot more bindings, and then it would no longer serve the purpose for vim/helix users. I don't think such a keymap is necessarily a bad idea, just that it didn't solve this issue. (It'd be a big effort to make a Gram keymap from scratch, but maybe it's worthwhile someday.)

Some thoughts on the implementation:

  • I was happy that I only needed to add this many bindings to get a usable environment without the bindings from another editor, but of course it's not perfect. Plenty of things still require mouse interaction, and it wasn't my intent to fix that, but as a long-time vim user, I think this feels pretty close to what I'd expect from a vim mode in an IDE. I may have more ideas for improvements over time!
  • The only "flights of fancy" (bindings not from vim) are the ones to toggle the docks, but I think there's in the right spirit and don't conflict with existing Gram keys. (The ctrl-w b and r bindings do conflict with vim hotkeys for window management, but Gram has different ways of doing those things.) I think there's definitely room to add more Gram-specific bindings similar to this.
  • The onboarding screen needed a button for the Minimal base keymap, so I chose the basic "code" icon for that. The existing rows were full, so I added a third row. The column counts have to match, and the type of each column has to match, meaning the second and third buttons had to have icons, so I just made a blank icon. Those buttons do nothing, of course.
Fixes #117 Hopefully the commit messages are mostly explanatory: (first commit is just a fix for emacs being neglected) ``` docs: correct base keymap to emacs and add missing emacs to list If you remove the base keymap from your user settings and restart, emacs will be selected, not VSCode. ``` ``` Add "minimal" base keymap This allows users to enable vim/helix keybinds without inheriting a full set of keybinds from another editor. It only includes a small set of bindings that are normally provided by another editor's binds and are missing from the vim/helix bindings, and that are not vim/helix-specific, meaning they don't care about editor mode and don't use vim/helix-style keyboard shortcuts. (Missing vim/helix-specific keys will be added to their bindings directly.) ``` ``` Add missing vim/helix keybindings for use with Minimal base Some basic editing functionality (enter for newline, backspace, etc.) was provided by other editors' keymaps, but if you use the Minimal base keymap, some basic functionality that depends on vim/helix modes or binding styles was still missing, and is provided here. ``` This result differs slightly from the discussion in #117 because of the need for some keys to check vim mode, which doesn't belong in a base keymap. Also, I named it "Minimal (for vim/helix)" in user-facing places because a general "Minimal" base keymap (that would also work for non-vim/helix users) would require a *lot* more bindings, and then it would no longer serve the purpose for vim/helix users. I don't think such a keymap is necessarily a bad idea, just that it didn't solve this issue. (It'd be a big effort to make a Gram keymap from scratch, but maybe it's worthwhile someday.) Some thoughts on the implementation: * I was happy that I only needed to add this many bindings to get a usable environment without the bindings from another editor, but of course it's not perfect. Plenty of things still require mouse interaction, and it wasn't my intent to fix that, but as a long-time vim user, I think this feels pretty close to what I'd expect from a vim mode in an IDE. I may have more ideas for improvements over time! * The only "flights of fancy" (bindings not from vim) are the ones to toggle the docks, but I think there's in the right spirit and don't conflict with existing Gram keys. (The ctrl-w b and r bindings do conflict with vim hotkeys for window management, but Gram has different ways of doing those things.) I think there's definitely room to add more Gram-specific bindings similar to this. * The onboarding screen needed a button for the Minimal base keymap, so I chose the basic "code" icon for that. The existing rows were full, so I added a third row. The column counts have to match, and the type of each column has to match, meaning the second and third buttons had to have icons, so I just made a blank icon. Those buttons do nothing, of course.
If you remove the base keymap from your user settings and restart, emacs
will be selected, not VSCode.
Owner
Copy link

Hi, great work!

Noticed one missed array size:

 Compiling remote_server v0.1.0 (/Users/krig/src/krig/gram/crates/remote_server)
error[E0308]: mismatched types
 --> crates/settings/src/base_keymap_setting.rs:72:52
 |
72 | pub const OPTIONS: [(&'static str, Self); 6] = [
 | ____________________________________________________^
73 | | ("VS Code", Self::VSCode),
74 | | ("Atom", Self::Atom),
75 | | ("JetBrains", Self::JetBrains),
... |
79 | | ("Minimal", Self::Minimal),
80 | | ];
 | |_____^ expected an array with a size of 6, found one with a size of 7
 |
 = note: expected array `[(&'static str, BaseKeymap); 6]`
 found array `[(&'static str, BaseKeymap); 7]`
Hi, great work! Noticed one missed array size: ``` Compiling remote_server v0.1.0 (/Users/krig/src/krig/gram/crates/remote_server) error[E0308]: mismatched types --> crates/settings/src/base_keymap_setting.rs:72:52 | 72 | pub const OPTIONS: [(&'static str, Self); 6] = [ | ____________________________________________________^ 73 | | ("VS Code", Self::VSCode), 74 | | ("Atom", Self::Atom), 75 | | ("JetBrains", Self::JetBrains), ... | 79 | | ("Minimal", Self::Minimal), 80 | | ]; | |_____^ expected an array with a size of 6, found one with a size of 7 | = note: expected array `[(&'static str, BaseKeymap); 6]` found array `[(&'static str, BaseKeymap); 7]` ```
Author
Contributor
Copy link

Ah, sorry about that; I'm not on a Mac so the conditional compilation didn't let me know I had missed it. Should be fixed now.

Ah, sorry about that; I'm not on a Mac so the conditional compilation didn't let me know I had missed it. Should be fixed now.
Owner
Copy link

@tjk wrote in #144 (comment):

Ah, sorry about that; I'm not on a Mac so the conditional compilation didn't let me know I had missed it. Should be fixed now.

No worries, I do that all the time but for Linux. My Linux box is so slow that I can't be bothered to test.. and it always bites me.

Looks great and all the tests are passing here, thank you!

@tjk wrote in https://codeberg.org/GramEditor/gram/pulls/144#issuecomment-11905713: > Ah, sorry about that; I'm not on a Mac so the conditional compilation didn't let me know I had missed it. Should be fixed now. No worries, I do that all the time but for Linux. My Linux box is so slow that I can't be bothered to test.. and it always bites me. Looks great and all the tests are passing here, thank you!
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
GramEditor/gram!144
Reference in a new issue
GramEditor/gram
No description provided.
Delete branch "tjk/gram:vim-keymap"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?