visidata
visidata copied to clipboard
Ability to customize the keybindings that are recognized while editing a cell value
In visidata/_input.py on line 607, the cell-edit keybindings are hardcoded. It would be nice if we could customize these values in a config file.
My motivating example: I do a lot of manual data entry, so when I'm finished typing the value in a particular row, I want to quickly move to the next row. The shortcut to do this is Shift+Down
, but this requires moving my hand from the numbers to the arrow keys; for a lot of data entry, this time wastage adds up fast! I want Ctrl+N
and Ctrl-P
to mean "next line" and "previous line" respectively, as these are much faster to type. I actually achieved this by modifying the source code and recompiling, but it would be nice if I didn't have to resort to such measures.
Thanks in advance! I'm really impressed by visidata; I only first heard of it a few hours ago. Wonderful software!
That's an interesting point. I imagine there's a good/historical reason for not exposing those keys for easy customization, but in case it helps it looks like you can still handle this with an addition to your ~/.visidatarc
file:
from functools import partialmethod
from visidata import Sheet
from visidata._input import acceptThenFunc
Sheet.editCell = partialmethod(Sheet.editCell, bindings={
"^N": acceptThenFunc('go-down', 'edit-cell'),
"^P": acceptThenFunc('go-up', 'edit-cell'),
})
It's a bit awkward compared to the more typical key bindings, but probably still less messy than maintaining a personal/local fork.
It's also possible that there's a different/better way to do this, or that this approach could break something else. :monocle_face:
@ajkerrigan You're a total pro at the monkey-patching! We need to change the keystrokes for input keybindings to the new-style Ctrl+N
etc. and I agree, we should find a better way to do this, or devise an API to let us. But the need to accept/cancel the current input complicates things. What do you think it should look like, @ei14 and @ajkerrigan?
we should find a better way to do this, or devise an API to let us. But the need to accept/cancel the current input complicates things. What do you think it should look like, @ei14 and @ajkerrigan?
Hmm one way might be to optimize for the "accept and do a thing" case, maybe with an option that maps keystrokes to an iterable of functions that run after accepting input? With these sample changes, the monkeypatching suggestion turns into:
vd.options.edit_accept_keybindings = {
"Ctrl+N": ("go-down", "edit-cell"),
"Ctrl+P": ("go-up", "edit-cell"),
}
I'm not sure if that's the best way to handle it or not (even if it is, the naming and description could probably use some work), but it does seem a wee bit friendlier. It may be making too many assumptions though, overindexed on this particular issue. So other ideas or tweaks are very welcome.