##// END OF EJS Templates
Add config option for vi mode
Thomas Kluyver -
Show More
@@ -1,4 +1,5 b''
1 1 from IPython.core.interactiveshell import InteractiveShell
2 from traitlets import Bool
2 3
3 4 from prompt_toolkit.completion import Completer, Completion
4 5 from prompt_toolkit.enums import DEFAULT_BUFFER
@@ -7,6 +8,8 b' from prompt_toolkit.history import InMemoryHistory'
7 8 from prompt_toolkit.shortcuts import create_prompt_application
8 9 from prompt_toolkit.interface import CommandLineInterface
9 10 from prompt_toolkit.key_binding.manager import KeyBindingManager
11 from prompt_toolkit.key_binding.vi_state import InputMode
12 from prompt_toolkit.key_binding.bindings.vi import ViStateFilter
10 13 from prompt_toolkit.keys import Keys
11 14 from prompt_toolkit.layout.lexers import PygmentsLexer
12 15 from prompt_toolkit.styles import PygmentsStyle
@@ -38,6 +41,10 b' class PTInteractiveShell(InteractiveShell):'
38 41
39 42 pt_cli = None
40 43
44 vi_mode = Bool(False, config=True,
45 help="Use vi style keybindings at the prompt",
46 )
47
41 48 def get_prompt_tokens(self, cli):
42 49 return [
43 50 (Token.Prompt, 'In ['),
@@ -47,10 +54,14 b' class PTInteractiveShell(InteractiveShell):'
47 54
48 55
49 56 def init_prompt_toolkit_cli(self):
50 kbmanager = KeyBindingManager.for_prompt()
57 kbmanager = KeyBindingManager.for_prompt(enable_vi_mode=self.vi_mode)
58 insert_mode = ViStateFilter(kbmanager.get_vi_state, InputMode.INSERT)
51 59 # Ctrl+J == Enter, seemingly
52 60 @kbmanager.registry.add_binding(Keys.ControlJ,
53 filter=HasFocus(DEFAULT_BUFFER) & ~HasSelection())
61 filter=(HasFocus(DEFAULT_BUFFER)
62 & ~HasSelection()
63 & insert_mode
64 ))
54 65 def _(event):
55 66 b = event.current_buffer
56 67 if not b.document.on_last_line:
General Comments 0
You need to be logged in to leave comments. Login now