Skip to content

Cursor moves unexpectedly after formatprg #18905

@EdwinChan

Description

@EdwinChan

Steps to reproduce

  1. Start vim as follows. The first -c makes the command 'formatprg' generates (e.g., :.,.+2!sed…) span multiple lines in the command window. The second -c creates an arbitrarily named mark in the document; the mark is required. The + is merely for convenience:
seq 1 40 | vim - -u 'NONE' \
  -c "let &l:formatprg='sed$(printf '%500s' '')p'" \
  -c 'normal! 20Gmz' \
  +10
  1. Run gq2j in normal mode on line 10, or any gq command over a range that includes at least 3 lines (so that, e.g., 3 lines filtered appears in :messages) before the mark but does not include the mark. Note that passing -c 'normal! gq2j' on the command line does not result in the bug.
  2. The cursor moves to the mark after running gq.

Expected behaviour

Running gq in any way other than specified keeps the cursor either at the beginning or the end of the filtered text.

Version of Vim

9.1 (2024 Jan 02, compiled Sep 05 2025 19:44:46) patches: 1-16, 647, 678, 697 (shipped with Ubuntu)

Environment

Operating system: Ubuntu 24.04.3 LTS on WSL 2.6.2.0 (Windows 11 Home 25H2)
Terminal: Windows Terminal 1.23.12811.0
Value of $TERM: xterm-256color
Shell: GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)

Logs and stack traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions