I stumbled on a behaviour which I don't understand. I'm using Bash and Vim 8.2.2434 in Debian 11.
To reproduce it, I created two new files in an empty directory:
foo.py
class Foo:
def __init__(self, foo):
self.foo = foo
def get_foo(self):
return self.foo
bar.py
import foo
class Bar:
def __init__(self, bar):
self.foo = Foo(bar)
def calc(self):
return 2 * self.foo.get_foo()
Now I run vim bar.py
and place the cursor here:
def calc(self):
return 2 * self.foo.get_foo()
^
Now I execute an external command, in the simplest case one that does nothing:
:!true
Upon the message Press ENTER or type command to continue
, I press i.
Now this output appears, it seems to list lines in the two files where the word foo
appears, where the cursor is currently on (when doing this with real code, the output may be longer and is paged with -- More --
showing at the bottom):
foo.py
1: 2 def __init__(self, foo):
2: 3 self.foo = foo
3: 6 return self.foo
bar.py
4: 5 self.foo = Foo(bar)
5: 8 return 2 * self.foo.get_foo()
After pressing Enter again, I notice that the cursor is now here (it has moved one position to the left):
def calc(self):
return 2 * self.foo.get_foo()
^
To exclude the possibility that any of my Vim settings or plugins have anything to do with it, I close Vim and start it again with vim -u NONE bar.py
.
If I now repeat the same steps, the output is a bit different (it doesn't include lines from foo.py anymore, which I hadn't opened, and it adds the line import foo
which it didn't show previously):
bar.py
1: 1 import foo
2: 5 self.foo = Foo(bar)
3: 8 return 2 * self.foo.get_foo()
The cursor has still moved one position to the left.
As another experiment, I rename my ~/.vim
directory so that Vim can't load my personal settings, but I omit the -u NONE
option again.
Now after pressing i it doesn't show any output, but enters insert mode, which is what I would expect from :help press-enter
:
-> Press ':' or any other Normal mode command character to start that command.
What is this feature and what does it have to do with running an external command? Why does it occur when using my own Vim settings or none at all, but not when using the default ones?
:help include-search
. And yes, it has nothing to do with running external commands. What you get is what you would expect after pressing]I
, see:help ]i
. FWIW, I can't reproduce your issue with$ vim -u NONE
or$ vim --clean
in 9.0.1276.[I
-u NONE
replicates the issue (for you; not for others??). You can try How to debug my vimrc, but it may be a weird escape-sequence bug, too.