onivim / libvim

libvim: The core Vim editing engine as a minimal C library

Home Page:https://v2.onivim.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Expose command state

glennsl opened this issue · comments

There's currently no way to inspect the command state, i.e. which keys have been punched in and what command is in the process of being built. Knowing this would be useful for a couple of features:

  1. Displaying the current command state, which characters and what count, if any, has been entered, in case you get distracted in the middle of something and forget.

  2. To provide contextual help. This will both reduce the need to memorize commands AND make it easier to learn them. For example, if g has been entered, the UI could display a list of possible characters to "complete" the command:

g - Go to top
t - Go to next tab
T - Go to previous tab
u - Convert to lowercase
U - Convert to uppercase
~ - Swap case
] - See all definitions

Technical details

The command state, at least in normal mode, is stored in state_current->context->ca, a cmdarg_T. state_current->context is a void* and will point to different data structures depending on mode, but normal mode is mostly what I'm interested in here (or "Normal", "Visual" and "Operator" I guess, according to get_real_state()).

A new function vimGetCommandState could return either the entire cmdarg_T struct, or a subset if that's easier to bind to from Reason. Or null if the stars aren't aligned.

This is a great suggestion, @glennsl ! Thank you! I like the idea of vimGetCommandState. Seems like this wouldn't be too hard to wire up - all the information is around.

Contextual help would be an amazing feature and help lower the learning curve & barrier to entry significantly.