Issue
I'm trying to understand some annoying behaviour from ipython. I have vi mode enabled, I can confirm this like so;
[ins] In [1]: from IPython import get_ipython
...: ipython = get_ipython()
...: ipython.editing_mode
Out[1]: 'vi'
Mostly it works, but if I hit esc then two other keys in quick succession, only the first of the two is treated as a "normal" mode command ([nav]
), the other one gets treated as an insert mode command ([ins]
).
For example, say the cursor is at the end of the line
[nav] In [2]: who = ["some", "person"]
and I hit the b
key 4 times quickly, the result is
[ins] In [2]: who = ["some", "personbbb"]
so the first press did what I expected, took the cursor back a word. Pressed 2,3 and 4 all acted in insert mode, resulting in "personbbb".
On the other hand, if I hit esc, wait a second or so, and then hit b
4 times I get exactly what I expect
[nav] In [2]: who = ["some", "person"]
and the cursor is by the 'e' in "some". Hitting esc multiple times also ensures I stay in normal mode properly, no matter how fast I hit keys.
Is this a setting somewhere?
What I've tried
All the sugestions in How do I use vi keys in ipython under *nix? just in case I wasn't setting 'vi' mode properly.
Also updating my ipython, in case it was a bug in this version.
Searching for questions about 'vi' mode in ipython. The one I've just listed is the main thing that comes up, but I'm pretty surprised that this behaviour hasn't been mentioned before?
What I'm using
My zsh version is 5.8.1 (x86_64-apple-darwin21.0).
My ipython version is 8.6.0
My
~/.inputrc
has
set editing-mode vi
set keymap vi
- My
~/.ipython/profile_default/ipython_config.py
has
c.TerminalInteractiveShell.editing_mode = 'vi'
(excluding comments)
I was torn between asking this here, and asking on the macOS stack exchange, because I don't know if this is an ipython issue, or a mac issue. I've only seen it on my mac using zsh.
Solution
This problem appears to be addressed in this issue in the IPython repo. For me the solution was to put the following line into the ipython_config.py
:
c.TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode = False
In Linux, the location of ipython_config.py
can be ~/.ipython/profile_default/ipython_config.py
.
Answered By - Mikhail Arkhipov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.