prompt-toolkit / pyvim

Pure Python Vim clone.
BSD 3-Clause "New" or "Revised" License
2.52k stars 160 forks source link

Ctrl+c does not exit insert mode #124

Closed bdd4329 closed 5 years ago

bdd4329 commented 5 years ago

My workflow involves using Ctrl+c to exit insert mode since it requires less movement than using Esc. Please add/fix support for exiting insert mode via Ctrl+c.

lieryan commented 5 years ago

It is is fairly simple to implement this in your .pyvimrc:

from prompt_toolkit.filters import ViInsertMode
from prompt_toolkit.key_binding.key_processor import KeyPress
from prompt_toolkit.keys import Keys

__all__ = (
    'configure',
)

def configure(editor):
    # Add custom key bindings:

    @editor.add_key_binding('c-c', filter=ViInsertMode())
    def _(event):
        event.cli.key_processor.feed(KeyPress(Keys.Escape))

Note that using C-c does not behave the same as Esc in vim; C-c is force switching to insert mode, not regular switch to normal mode. Using C-c to quit insert mode is generally a bad habit. Try using C-[ instead if your Esc key is hard to use, or try remapping keys like Caps Lock or jj. There is an example of how to do this on the example .pyvimrc.

bdd4329 commented 5 years ago

Thanks, this works perfectly. Also, thanks for pointing out the difference in Ctrl+c vs Ctrl+[. I always found Ctrl+c faster to type, and I don't normally use vim plugins so this doesn't usually effect me. However, it is good to know.