-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipython_startup_keybindings.py
30 lines (28 loc) · 1.16 KB
/
ipython_startup_keybindings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This is the keybinding to fix "Option(Alt) + Arrowkeys" under iTerm2's xterm Key Preset.
# Since from IPython 5+, it uses pyreadline and doesn't honor inputrc anymore.
# To activate this, link this file under ~/.ipython/profile_default/startup/
# This is tested under IPython 6.0 with Python 3.6 / Python 2.7.14
from IPython import get_ipython
from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.bindings.named_commands import get_by_name
____ip = get_ipython()
# print(ip)
if getattr(____ip, 'pt_cli', None):
# Meta + ^
____ip.pt_cli.application.key_bindings_registry.add_binding(
Keys.Escape, *u'[1;9A')(
get_by_name('previous-history'))
# Meta + v
____ip.pt_cli.application.key_bindings_registry.add_binding(
Keys.Escape, *u'[1;9B')(
get_by_name('next-history'))
# Meta + ->
____ip.pt_cli.application.key_bindings_registry.add_binding(
Keys.Escape, *u'[1;9C')(
get_by_name('forward-word'))
# Meta + <-
____ip.pt_cli.application.key_bindings_registry.add_binding(
Keys.Escape, *u'[1;9D')(
get_by_name('backward-word'))
del get_ipython, Keys, get_by_name
del ____ip