2017-03-16 7 views
0

私はIPython Viモードを使用しており、IPythonは多くのデフォルトキーマッピングを設定していますhere。私は研究herehereを行って、KeyBindingManagerを使って新しいキーバインディングを作成できることを見出しました。IPython Viモードで存在する既定のキーバインディングを置き換える方法はありますか?

ただし、作成したいバインディングが存在する場合は動作できません。 tは私が動作しない結合、hereをマッピングされているので

from prompt_toolkit.filters.cli import ViNavigationMode, ViMode 
from prompt_toolkit.filters import Always, IsReadOnly 

# create `handle` 
from IPython import get_ipython 
ip = get_ipython() 
if getattr(ip, 'pt_cli'): 
    registry = ip.pt_cli.application.key_bindings_registry 
    handle = registry.add_binding 

navigation_mode = ViNavigationMode() & ViMode() & Always() 

@handle('t', filter=navigation_mode) 
def _(event): 
    """ 
    Go up, but if we enter a new history entry, move to the start of the 
    line. 
    """ 
    event.current_buffer.auto_up(
     count=event.arg, go_to_start_of_line_if_history_changes=True) 

:たとえば、私は~/.ipython/profile_default/startup/vikeys.pyでいくつかのコードを記述します。

私も以下のコードでhandleを交換しようとしたが、全く効果がありませんでした:

# create `handle` 
from prompt_toolkit.key_binding.manager import KeyBindingManager 
manager = KeyBindingManager.for_prompt() 
handle = manager.registry.add_binding 

ので、IPython内の既存のキーバインディングを交換する方法はありますか?

答えて

0

同じ問題に会う人を助けるために、自分自身で質問に答えます。

ソースコードを読んだあと、handleに引数eager=Trueを追加すると、デフォルトのキーバインドが上書きされることがわかりました。

Hereは、Dvorakユーザーのデフォルトのナビゲーションキーを置き換える例です。

関連する問題