[vim/vim] keep '[ and ] marks above line 1 (PR #19061)

18 views
Skip to first unread message

glepnir

unread,
Jan 2, 2026, 5:47:06 AM (4 days ago) Jan 2
to vim/vim, Subscribed

Problem: deleting lines could move '[ or '] to line 0

Solution: clamp op start/end lnum to at least 1

related neovim/neovim#30593


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19061

Commit Summary

  • 7b283d6 fix(mark): keep '[ and ] marks above line 1

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061@github.com>

Christian Brabandt

unread,
Jan 2, 2026, 8:24:14 AM (4 days ago) Jan 2
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19061)

that test does not currently fail. Also shouldn't it verify the mark positions?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3705314155@github.com>

Christian Brabandt

unread,
Jan 2, 2026, 8:28:51 AM (4 days ago) Jan 2
to vim/vim, Subscribed

Closed #19061 via 4fe7301.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/issue_event/21827531925@github.com>

Christian Brabandt

unread,
Jan 2, 2026, 8:36:55 AM (4 days ago) Jan 2
to vim/vim, Subscribed

Reopened #19061.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/issue_event/21827606471@github.com>

dkearns

unread,
Jan 2, 2026, 9:46:50 AM (4 days ago) Jan 2
to vim/vim, Subscribed
dkearns left a comment (vim/vim#19061)

These marks should arguably remain unset when calling the command on an empty buffer as no text was changed. I say arguably because Vim's handling of commands on empty buffers is generally a bit suspect.

I would strongly consider leaving this for another day given the release schedule, rather than baking in a possibly incorrect fix.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3705509407@github.com>

glepnir

unread,
Jan 2, 2026, 10:44:05 PM (3 days ago) Jan 2
to vim/vim, Subscribed
glepnir left a comment (vim/vim#19061)

The marks are already being set by op_colon (b_op_start/end = oap->start/end). do_filter then subtracts linecount without checking, making them invalid (lnum=0). Whether marks should be set on empty buffers is debatable, but once set, they
shouldn't become invalid. This just adds bounds checking to the adjustment.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3706661988@github.com>

glepnir

unread,
Jan 2, 2026, 10:48:46 PM (3 days ago) Jan 2
to vim/vim, Subscribed
glepnir left a comment (vim/vim#19061)

that test does not currently fail.

sry WDHYM. before v:errmsg it's E20 now it's empty .


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3706664489@github.com>

dkearns

unread,
Jan 3, 2026, 3:38:28 AM (3 days ago) Jan 3
to vim/vim, Subscribed
dkearns left a comment (vim/vim#19061)

I understand the PR I'm just concerned about committing to a fix that might be less than optimal and then getting hit with backward compatibility requirements when trying to normalise the behaviour with other commands in the future. It's broken now so it's unlikely anyone is relying on it. However, they might be relying on the error.

Having said that I had a quick look and while there's varying behaviour (d at least leaves the marks unset) most commands appear to set these marks to (1, 0) after an operation on an empty buffer without emitting an error, so it's probably reasonable.

Before your change only one mark was set, now they both are, and that should be confirmed by the test.

:marks []
mark line  col file/text
 [      1    0

vs

:marks []
mark line  col file/text
 [      1    0
 ]      1    0


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3706896621@github.com>

glepnir

unread,
Jan 3, 2026, 3:47:34 AM (3 days ago) Jan 3
to vim/vim, Push

@glepnir pushed 1 commit.

  • 785f99c fix(mark): keep '[ and ] marks above line 1


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/before/7b283d684d15968ce8ce414c53827c69b56853f4/after/785f99c3b82e7235ee3e88a3c9e0df6d014f3856@github.com>

glepnir

unread,
Jan 3, 2026, 3:50:15 AM (3 days ago) Jan 3
to vim/vim, Push

@glepnir pushed 1 commit.

  • ba40e95 fix(mark): keep '[ and ] marks above line 1

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/before/785f99c3b82e7235ee3e88a3c9e0df6d014f3856/after/ba40e959c1358b18ef7c6c11b698721943e26a3a@github.com>

Christian Brabandt

unread,
Jan 3, 2026, 6:12:25 AM (3 days ago) Jan 3
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19061)

If I run the new test right now, without your change to ex_cmds.c, it doesn't fail. That might be fixed now with your latest commit, let me retest it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3706981533@github.com>

glepnir

unread,
Jan 3, 2026, 6:26:17 AM (3 days ago) Jan 3
to vim/vim, Subscribed
glepnir left a comment (vim/vim#19061)

weird 🤔 I can get failed on master
image.png (view on web)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3706988402@github.com>

Christian Brabandt

unread,
Jan 3, 2026, 7:28:32 AM (3 days ago) Jan 3
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19061)

There are a few issues here:

  • type (also I think formatprg should not be set to cmd /c ) on MS-Windows does not work, because it does not handle stdin correctly. Funnily, it seems more works.
  • I think we should probably return early for an empty buffer in do_filter() anyhow, this also avoids that the buffer is marked as modified (for a no-op)

The test should probably look like this:

func Test_mark_formatprg_on_empty()
  new
  if has('win32')
    setl formatprg=more
  else
    setl formatprg=cat
  endif
  call assert_equal([0, 0], [line("'["), col("'[")])
  call assert_equal([0, 0], [line("']"), col("']")])
  try
    norm! gqG
  catch
    call assert_report("gqG on empty buffer should not fail")
  endtry
  call assert_true(empty(v:errmsg))
  call assert_equal([0, 0], [line("'["), col("'[")])
  call assert_equal([0, 0], [line("']"), col("']")])
  call assert_false(&modified)
  bwipe!
endfunc


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3707022445@github.com>

dkearns

unread,
Jan 3, 2026, 7:51:41 AM (3 days ago) Jan 3
to vim/vim, Subscribed
dkearns left a comment (vim/vim#19061)
  • I think we should probably return early for an empty buffer in do_filter() anyhow, this also avoids that the buffer is marked as modified (for a no-op)

I thought this might be out of scope for the release but if it's not, there's some inconsistencies in command behaviour. <, for example, also sets 'modified' on an empty buffer. It really needs a full audit.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3707034351@github.com>

Christian Brabandt

unread,
Jan 3, 2026, 8:12:46 AM (3 days ago) Jan 3
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19061)

Yeah agree, let's hold off until after the release


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/c3707047074@github.com>

glepnir

unread,
Jan 3, 2026, 11:19:58 PM (2 days ago) Jan 3
to vim/vim, Push

@glepnir pushed 1 commit.

  • 8aa393f fix(mark): keep '[ and ] marks above line 1

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/before/ba40e959c1358b18ef7c6c11b698721943e26a3a/after/8aa393ff85094928f2dff66e4c0d738383bcfbf1@github.com>

glepnir

unread,
Jan 4, 2026, 11:11:44 PM (2 days ago) Jan 4
to vim/vim, Push

@glepnir pushed 1 commit.

  • dbfc0bd fix(mark): keep '[ and ] marks above line 1

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19061/before/8aa393ff85094928f2dff66e4c0d738383bcfbf1/after/dbfc0bd11d2fa4b4e96c5ac1e1d71754aa5310ae@github.com>

Reply all
Reply to author
Forward
0 new messages