-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipython_config.py
67 lines (44 loc) · 1.92 KB
/
ipython_config.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import IPython
from prompt_toolkit.key_binding.vi_state import InputMode, ViState
def get_input_mode(self):
if sys.version_info[0] == 3:
from prompt_toolkit.application.current import get_app
app = get_app()
# Decrease input flush timeout from 500ms to 10ms.
app.ttimeoutlen = 0.01
# Decrease handler call timeout from 1s to 250ms.
# app.timeoutlen = 0.25
app.timeoutlen = 0.25
return self._input_mode
def set_input_mode(self, mode):
shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6)
cursor = "\x1b[{} q".format(shape)
if hasattr(sys.stdout, "_cli"):
write = sys.stdout._cli.output.write_raw
else:
write = sys.stdout.write
write(cursor)
sys.stdout.flush()
self._input_mode = mode
ip = IPython.get_ipython()
def switch_to_navigation_mode(event):
vi_state = event.cli.vi_state
vi_state.input_mode = InputMode.NAVIGATION
if getattr(ip, 'pt_app', None):
registry = ip.pt_app.key_bindings
registry.add_binding(u'j',u'k',
filter=(HasFocus(DEFAULT_BUFFER)
& ViInsertMode()))(switch_to_navigation_mode)
c.TerminalInteractiveShell.editing_mode = "vi"
c.TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode = False
c.TerminalInteractiveShell.timeoutlen = 0.25
c.TerminalInteractiveShell.highlighting_style = 'solarized-dark'
# def junk():
# c.TerminalInteractiveShell.prompt_includes_vi_mode = True
# keybindings = IPython.get_ipython().pt_app.key_bindings
# vi_navigation_mode_keybinding = partial(keybindings.add, filter=HasFocus(DEFAULT_BUFFER) & ViNavigationMode())
# vi_insert_mode_keybinding = partial(keybindings.add, filter=HasFocus(DEFAULT_BUFFER) & ViInsertMode())
# @vi_insert_mode_keybinding("k", "k")
# def switch_to_navigation_mode(event):
# event.cli.vi_state.input_mode = InputMode.NAVIGATION