Does anybody have ideas about using emacs
/ vim
key binding for Preview.app
to browser pdf
files and how?
4 Answers
You can edit the "Up" and "Down" keyboard shortcuts by going to System Preferences / Keyboard / Application Shortcuts, add a new shortcut for Preview.app. I've mapped Option-J to down, Option-K to up. It won't let you map just J and K, for some reason. But at least you can now browse a PDF without leaving the home row.
-
1This is a great tip! If only there was a way to get it to scroll smoothly. I always lose track of where I was when going a full page down.– sjyCommented May 22, 2014 at 11:37
-
@ted "Up" and "Down" do not scroll. I'd like the behavior of the up/down arrow keys. How do you know "Up" and "Down is the exact name of the shortcut you have to put in the preference? Is that listed anywhere? If we have that list, maybe we can find out what the shortcut for "Scroll Up" and "Scroll Down" is. Commented May 31, 2020 at 18:47
As @tty suggested, using Karabiner is brilliant. I made some extra rules.
You can navigate using HJKL and zoom using FDER. Read the file for more information.
Here is my private.xml
:
<?xml version="1.0"?>
<root>
<appdef>
<appname>PREVIEW</appname>
<equal>com.apple.Preview</equal>
</appdef>
<item>
<name>Vi Navigation in Preview</name>
<identifier>private.preview.vinav</identifier>
<only>PREVIEW</only>
<uielementrole_not>AXTextField, AXTextArea</uielementrole_not>
<modifier_only>
ModifierFlag::NONE,
ModifierFlag::SHIFT_L | ModifierFlag::NONE,
ModifierFlag::SHIFT_R | ModifierFlag::NONE,
</modifier_only>
<appendix>Navigate using the HJKL keys</appendix>
<autogen>__KeyToKey__ KeyCode::J, KeyCode::CURSOR_DOWN</autogen>
<autogen>__KeyToKey__ KeyCode::K, KeyCode::CURSOR_UP</autogen>
<autogen>__KeyToKey__ KeyCode::H, KeyCode::CURSOR_LEFT</autogen>
<autogen>__KeyToKey__ KeyCode::L, KeyCode::CURSOR_RIGHT</autogen>
</item>
<item>
<name>Vi Zoom in Preview</name>
<identifier>private.preview.vizoom</identifier>
<only>PREVIEW</only>
<uielementrole_not>AXTextField, AXTextArea</uielementrole_not>
<modifier_only>
ModifierFlag::NONE,
ModifierFlag::SHIFT_L | ModifierFlag::NONE,
ModifierFlag::SHIFT_R | ModifierFlag::NONE,
</modifier_only>
<appendix>Zoom using E/R: out/in</appendix>
<appendix>Zoom to fit: F</appendix>
<appendix>Zoom to 100%: D</appendix>
<autogen>__KeyToKey__ KeyCode::F, KeyCode::KEYPAD_9, VK_COMMAND</autogen>
<autogen>__KeyToKey__ KeyCode::D, KeyCode::KEYPAD_0, VK_COMMAND</autogen>
<autogen>__KeyToKey__ KeyCode::R, KeyCode::KEYPAD_PLUS, VK_COMMAND</autogen>
<autogen>__KeyToKey__ KeyCode::E, KeyCode::KEYPAD_MINUS, VK_COMMAND</autogen>
</item>
</root>
-
It had worked perfectly, but a few weeks ago it stopped working. Do you have any idea why? Commented Aug 30, 2015 at 21:37
-
1No, I'm not using this anymore. I assume you installed an updated version of Karabiner? If you find the solution feel free to edit. Or let me know what to change. Commented Aug 31, 2015 at 15:50
-
It turns out that this file is case sensitive so the Preview identifier should be
com.apple.Preview
; notcom.apple.preview
. Commented Oct 12, 2015 at 17:11 -
Updating this answer with my latest findings, since there's a newer version of karabiner. After following the installation steps, I went ahead and installed the system wide vimium shortcut keys profile. This gives me vimium like mechanics throughout the system (MIND BLOW!!!). I removed some slippery slope shortcuts; such as
x
which maps tocmd-q
and other shortcuts. But the config file is very simple to modify and is located under~/.config/karabiner/karabiner.json
. Commented Apr 21, 2019 at 21:12
Use this
Very excellent!!!
I found it recently.
-
2Answers on Ask Different need to be more than just a link. It's okay to include a link, but please also show how the recommended product can actually be used to solve the problem described in the question. The more specific an answer is in regards of the question, the more useful it is for others.– nohillside ♦Commented Jan 23, 2014 at 7:49
Self-plug – I’ve made a Karabiner rule that adds vim jk bindings to Preview. I didn’t want to use the other Karabiner rules that added systemwide vim bindings.
https://github.com/xrisk/preview-vim
To use: copy the preview-vim.json
file from the repository (or take the copy from below), paste it in your ~/.config/karabiner/assets/complex_modifications
, and then enable the rule from Karabiner.
{
"title": "Map jk in Preview",
"rules": [
{
"description": "map jk",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "j"
},
"to": [
{
"key_code": "down_arrow"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": ["^com.apple.Preview$"]
}
]
},
{
"type": "basic",
"from": {
"key_code": "k"
},
"to": [
{
"key_code": "up_arrow"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": ["^com.apple.Preview$"]
}
]
}
]
}
]
}
Contributions are welcome!
Also sidenote: you might want to look into using zathura; it might fit your use-case.