私はIPython Viモードを使用しており、IPythonは多くのデフォルトキーマッピングを設定していますhere。私は研究hereとhereを行って、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内の既存のキーバインディングを交換する方法はありますか?