Skip to content

:delete reports one fewer line when deleting the entire buffer #21049

Description

@gnarendran

Steps to reproduce

When :delete deletes all lines in a buffer, the reported number of fewer lines is one less than the number of lines actually deleted.

For example, with a four-line buffer, deleting 1,$ removes all four lines, but reports 3 fewer lines. Deleting 2,$ from the same four-line buffer correctly reports 3 fewer lines.

Minimal reproduction:

function! CmdMsg(cmd) abort
	" First force the preceding change into a separate undo block.
	let &g:undolevels = &g:undolevels

	let l:msg = ''
	redir => l:msg
	execute 'silent ' . a:cmd
	redir END
	echomsg printf('Message from "%s": ', a:cmd) . trim(l:msg)
endfunction

call setline(1, ['one', 'two', 'three', 'four'])
call CmdMsg('1,$delete')
call CmdMsg('undo')
call CmdMsg('2,$delete')
call getchar()
quit!

Output of:
vi --clean -u theAboveScript

Message from "1,$delete": 3 fewer lines
Message from "undo": 4 more lines; before #2  0 seconds ago
Message from "2,$delete": 3 fewer lines

The first command deletes all four lines, leaving the buffer's required empty line, but the message appears to report the change in buffer line count rather than the number of lines actually deleted.

The second deletion is a useful comparison: it deletes three lines and correctly reports 3 fewer lines.

Expected behaviour

When :delete makes the buffer empty, it should correctly report the number of fewer lines, like in cases when buffer doesn't become empty.

Version of Vim

vim 9.2.920

Environment

Fedora44
XTerm(406)
xterm-256color
bash

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