RyotaUshio / obsidian-pdf-plus

The most Obsidian-native PDF annotation, viewing & editing tool ever. Comes with optional Vim keybindings.
https://ryotaushio.github.io/obsidian-pdf-plus/
MIT License
712 stars 15 forks source link

[FR] Zathura/Vim Style Bindings #119

Closed aidanmaney closed 3 months ago

aidanmaney commented 6 months ago

Describe your request

PDF viewers like Zathura support Vim-style bindings for search, navigation, etc.

Since many Obsidian users (myself included) enjoy the built-in Vim-mode in Obsidian, it would be nice to navigate PDFs in much the same way.

My initial idea would be to capture input(s) on a PDF page and map it to the corresponding key(s) e.g. the page-up/down and home/end keys and either re-use the existing Vim command bar for search or add a modal.

RyotaUshio commented 6 months ago

I personally don't use Vim key bindings, so I'm not familiar with them (although I know some very basic stuff) and I'm not sure what keys should be assigned to what functionality in the case of PDF viewers.

If you could list all the keys and the corresponding functionality that you want to have in detail, I might be able to add this feature (although the priority is not very high, unfortunately). For example, should j scroll to the next page or do the same thing as the space key does currently?

aidanmaney commented 6 months ago

Apologies for the slow response.

Referencing this cheat sheet I think the following subset of mappings would be useful:

Key/Chord Action
J Go to next page
K Go to previous page
gg Go to first page
Shift + G Go to last page
Shift + H Go to top of current page
Shift + L Go to bottom of current page
Ctrl + C or Esc Abort (e.g. stop capturing input to search bar)
Control + N or Enter Go to and highlight next match
Shift + Control + N or Shift + Enter Go to and highlight previous match
+ Zoom in
- Zoom out
= Zoom to original size
/ Search for text (forward in document)
? Search for text (backward in document)
: Enter command mode (with commands to be added later)

To answer your question I would have j put the viewport at the top of the next page rather than move a set distance like space does now.

Thank you for considering this addition!

RyotaUshio commented 6 months ago

Thanks, a subset of your list has been experimentally supported in 0.39.10.

RyotaUshio commented 5 months ago

0.39.17 added the support for y (copy the selected text).

BTW Recently, I've started learning vim myself and found it very attractive. I hope I will be able to support more and more key bindings in the future.

RyotaUshio commented 5 months ago

Currently, PDF++'s vim support is kinda hacky. It uses Scope, which isn't supposed to be used with multi-char key bindings.

https://github.com/RyotaUshio/obsidian-pdf-plus/blob/main/src/vim.ts

Given the nature of the Scope class, it's not easy to support complex key bindings like 10g (go to page 10). I'd appreciate any help from those who know the right way.

RyotaUshio commented 4 months ago

From the next version (0.39.25), j/k/h/l will scroll the page rather than take you to the next/previous page. This is the identical behavior to Zathura. To go to the next/previous pages, use J/K/H/L instead. => from 0.39.26, use J/K. H and L will be aliases for ^ and $, respectively, which scrolls the page to the top/bottom.

RyotaUshio commented 4 months ago

The next version (0.39.25) will also add the support for

RyotaUshio commented 4 months ago

I found a related thread on the forum: https://forum.obsidian.md/t/vim-movement-on-pdf-reader/65198

RyotaUshio commented 4 months ago

Currently, PDF++'s vim support is kinda hacky. It uses Scope, which isn't supposed to be used with multi-char key bindings.

https://github.com/RyotaUshio/obsidian-pdf-plus/blob/main/src/vim.ts

Given the nature of the Scope class, it's not easy to support complex key bindings like 10g (go to page 10). I'd appreciate any help from those who know the right way.

I somehow managed to get this kind of commands to work! For example, you will be able to do

from the next version.

RyotaUshio commented 3 months ago

I believe PDF++'s vim mode is now powerful enough to close this issue. For requesting a new vim feature or reporting bugs, please create a new issue. Thank you!