0

I open Vim and add the following lines to a buffer (call this state INITIAL):

xx xx xxx xx xxxx xx xxxxx xxxxxxxx xxxxx xxxxxxxxxxx x xxxxx xxx xxxx xxx x
xx xxxxxx xxx xxxxxxx xxxxxx xx x xxx xx xxx xxxxxx xx xxxxxx xx xxx xxx xx
xx xxxxx xxxxxxx xxxxxxxxx xxxxxxxxx xx xxx xxxxx xxxx xx xx xxxx xxxx xxx xx
xx xxxx xx x xxxxxxxx xxxxxxxx xx xx xxxx x xxxxxxx xxx xxx xxx xxx xxx xxx xxx
xx xxx xxx xxx xxx xxxx

I then go to the end of the buffer and enter insert mode (GA). I then type <C-O>gqip. The buffer changes to (call this state A):

xx xx xxx xx xxxx xx xxxxx xxxxxxxx xxxxx xxxxxxxxxxx x xxxxx xxx xxxx xxx x xx
xxxxxx xxx xxxxxxx xxxxxx xx x xxx xx xxx xxxxxx xx xxxxxx xx xxx xxx xx xx
xxxxx xxxxxxx xxxxxxxxx xxxxxxxxx xx xxx xxxxx xxxx xx xx xxxx xxxx xxx xx xx
xxxx xx x xxxxxxxx xxxxxxxx xx xx xxxx x xxxxxxx xxx xxx xxx xxx xxx xxx xxx xx
xxx xxx xxx xxx xxxx

Still in insert mode, I type <C-O>gqip again. The buffer changes to (call this state B):

xx xx xxx xx xxxx xx xxxxx xxxxxxxx xxxxx xxxxxxxxxxx x xxxxx xxx xxxx xxx x xx
xxxxxx xxx xxxxxxx xxxxxx xx x xxx xx xxx xxxxxx xx xxxxxx xx xxx xxx xx xx
xxxxx xxxxxxx xxxxxxxxx xxxxxxxxx xx xxx xxxxx xxxx xx xx xxxx xxxx xxx xx xx
xxxx xx x xxxxxxxx xxxxxxxx xx xx xxxx x xxxxxxx xxx xxx xxx xxx xxx xxx xxx
xx xxx xxx xxx xxx xxxx

Still in insert mode, I type <C-O>gqip again. The buffer changes back to A. It may be hard to tell, but A and B are actually distinct. Still in insert mode, if I keep typing <C-O>gqip, the buffer state keeps toggling between A and B. The state progression is therefore INITIAL → A → B → A → B → A → B → ... .

When I try the above in normal mode, the state progression is INITIAL → A → A → A → A → ... (which is what I would expect).

(All of the above works if I use gwip, gqap, gwap in place of gqip.)

I'm not sure if this is a bug or if there's some odd subtlety to Vim's commands that I've never noticed before. I thought gqip was supposed to be idempotent no matter what mode I ran it from.

My question is: What is going on here?

(If you're wondering why all the text is xs, it's because I first noticed this behavior while working on some confidential code, and then replaced everything with xs so I could ask this question publicly.)

2
  • 2
    FWIW #1, the mode you are in after you press <C-o> in insert mode is called "insert normal mode". FWIW #2, there is no promise of idempotency made anywhere in the doc. FWIW #3, I think you have found a bug… that you should report.
    – romainl
    Feb 11 at 21:15
  • @romainl Thank you, I've reported it to github.com/neovim/neovim/issues/22250 (not sure if I need to separately report it to the Vim repo).
    – IssaRice
    Feb 13 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.