From 5c6aa5ea5ad94ae0f40d8e04faa348a7003ef8cb 2018-10-13 00:03:06 From: Matthias Bussonnier Date: 2018-10-13 00:03:06 Subject: [PATCH] Give some love to the VI mode. Improve #11329, still likely need a magic to make editign mode easier to toggle --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 35cb069..e26008a 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -12,7 +12,7 @@ from IPython.utils.terminal import toggle_set_term_title, set_term_title from IPython.utils.process import abbrev_cwd from traitlets import ( Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union, - Any, + Any, validate ) from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode @@ -131,6 +131,23 @@ class TerminalInteractiveShell(InteractiveShell): highlighting. To see available styles, run `pygmentize -L styles`.""" ).tag(config=True) + @validate('editing_mode') + def _validate_editing_mode(self, proposal): + if proposal['value'].lower() == 'vim': + proposal['value']= 'vi' + elif proposal['value'].lower() == 'default': + proposal['value']= 'emacs' + + if hasattr(EditingMode, proposal['value'].upper()): + return proposal['value'].lower() + + return self.editing_mode + + + @observe('editing_mode') + def _editing_mode(self, change): + u_mode = change.new.upper() + self.pt_app.editing_mode = u_mode @observe('highlighting_style') @observe('colors') diff --git a/IPython/terminal/prompts.py b/IPython/terminal/prompts.py index ce8c169..6b7b7cc 100644 --- a/IPython/terminal/prompts.py +++ b/IPython/terminal/prompts.py @@ -13,8 +13,15 @@ class Prompts(object): def __init__(self, shell): self.shell = shell + def vi_mode(self): + if self.shell.pt_app.editing_mode == 'VI': + return '['+str(self.shell.pt_app.app.vi_state.input_mode)[3:6]+'] ' + return '' + + def in_prompt_tokens(self): return [ + (Token.Prompt, self.vi_mode() ), (Token.Prompt, 'In ['), (Token.PromptNum, str(self.shell.execution_count)), (Token.Prompt, ']: '),