I'm new to visidata so this might very easily be me, but when I add the following to my .visidatarc per the https://visidata.org/docs/customize/ page, the new command is not working.
globalCommand('^D', 'scroll-halfpage-down', ''sheet.topRowIndex += nVisibleRows//2')
Note, it's not that it's ignoring my .visidatarc -- I tried adding it via bindkey, but then it complains about scroll-halfpage-down not being a valid command.
Expected result
I'd expect it to scroll down half a page, instead it does the default behavior (saves a log).
Additional context
Version is 1.5.2
Hi @nathanbraun!
This was fun to figure out. ^^
There are a couple of things going on. We can use this debugging to improve the docs.
~/.visidatarc in v1.5.2.So since you are overwriting an existing keystroke, I would modify from globalCommand to: Sheet.addCommand.
There is a minor bug in what you sent me. I see a double '' preceding the execstr.
Your command will not work as it is written out, because of nuances in the cursorRowIndex. The cursor position takes priority over the top row index. This is because if you go to a specific row (or column), you don't want the size/shape of your window to change that. Everything in VisiData is arranged so that changing your window dimensions or shifting the 'viewport' will keep the cursor in the same place. So we need to also update the cursor! We provide the api cursorDown(nRows) for that purpose.
Tl;dr this should work
Sheet.addCommand('^D', 'scroll-halfpage-down', 'cursorDown(nVisibleRows//2); sheet.topRowIndex += nVisibleRows//2')
We are steadily improving the documention for 2.0, so more of this will be transparent, and I am going to add this stuff there. =D
Thanks for making an issue!
Awesome, thank you! That works!
Note I got what I typed (including the mistaken double ') directly off the https://visidata.org/docs/customize/ page, so sounds like that page might need to be updated?
One more question -- if I wanted to scroll a half page up with ^U (like in Vim) -- how would I do that? I tried:
Sheet.addCommand('^U', 'scroll-halfpage-up', 'cursorUp(nVisibleRows//2); sheet.topRowIndex -= nVisibleRows//2')
but that didn't work.
This is just a guess (you should view the actual error using Ctrl+E), but try cursorDown(-X) instead of cursorUp(X).
That works thank you!
Note I got what I typed (including the mistaken double ') directly off the https://visidata.org/docs/customize/ page, so sounds like that page might need to be updated?
Hehe. You are right. Thanks for calling it out! I will go update it now. =)
Updated! http://visidata.org/docs/customize/