[vim/vim] Backward paragraph motion (i.e., {) does not behave as expected for one-line buffers (Issue #13780)

13 views
Skip to first unread message

Edwin Chan

unread,
Dec 26, 2023, 1:33:55 PM12/26/23
to vim/vim, Subscribed

Steps to reproduce

  1. Create a buffer with a single line of arbitrary text
  2. Place the cursor anywhere on the line and perform any of the following actions:
    a. Press }: The cursor jumps to the end of the line
    b. Press {: The cursor unexpectedly jumps to the end of the line
    c. Press d, y, v, etc., followed by either } or {: The behavior is similar to the two cases above

Expected behaviour

If there are multiple non-empty lines (i.e., a single paragraph) in the buffer, } jumps to the end of the buffer and { jumps to the beginning. Therefore, { should similarly jump to the beginning of the buffer when there is only one line.

See also https://vi.stackexchange.com/q/43730 for related discussion.

Version of Vim

8.2.2121

Environment

Operating system: Ubuntu 22.04.3 LTS
Terminal: GNOME Terminal 3.44.0
Value of $TERM: xterm-256color
Shell: GNU bash, version 5.1.16(1)-release

Logs and stack traces

No response


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

Gary Johnson

unread,
Dec 27, 2023, 5:26:31 AM12/27/23
to reply+ACY5DGEYCXTQHH22DC...@reply.github.com, vim...@googlegroups.com
On 2023-12-26, Edwin Chan wrote:
> Steps to reproduce
>
> 1. Create a buffer with a single line of arbitrary text
> 2. Place the cursor anywhere on the line and perform any of the following
> actions:
> a. Press }: The cursor jumps to the end of the line
> b. Press {: The cursor unexpectedly jumps to the end of the line
> c. Press d, y, v, etc., followed by either } or {: The behavior is similar
> to the two cases above
>
> Expected behaviour
>
> If there are multiple non-empty lines (i.e., a single paragraph) in the buffer,
> } jumps to the end of the buffer and { jumps to the beginning. Therefore, {
> should similarly jump to the beginning of the buffer when there is only one
> line.
>
> See also https://vi.stackexchange.com/q/43730 for related discussion.
>
> Version of Vim
>
> 8.2.2121

This bug is also in the oldest version of vim I have already
compiled, 7.2.330.

If I understand the original author's intent, then the following
patch to 9.0.2185 seems to fix it. I may have missed something, but
I ran "make test" before and after the fix and the same tests failed
both times, so this fix doesn't break anything being tested.

Regards,
Gary


diff --git a/src/textobject.c b/src/textobject.c
index b315d0320..d4380b7cf 100644
--- a/src/textobject.c
+++ b/src/textobject.c
@@ -226,7 +226,7 @@ findpar(
if (both && *ml_get(curr) == '}') // include line with '}'
++curr;
curwin->w_cursor.lnum = curr;
- if (curr == curbuf->b_ml.ml_line_count && what != '}')
+ if (curr == curbuf->b_ml.ml_line_count && what != '}' && dir > 0)
{
char_u *line = ml_get(curr);


vim-dev ML

unread,
Dec 27, 2023, 5:26:51 AM12/27/23
to vim/vim, vim-dev ML, Your activity

On 2023-12-26, Edwin Chan wrote:
> Steps to reproduce
>
> 1. Create a buffer with a single line of arbitrary text
> 2. Place the cursor anywhere on the line and perform any of the following

> actions:
> a. Press }: The cursor jumps to the end of the line
> b. Press {: The cursor unexpectedly jumps to the end of the line
> c. Press d, y, v, etc., followed by either } or {: The behavior is similar
> to the two cases above
>
> Expected behaviour
>
> If there are multiple non-empty lines (i.e., a single paragraph) in the buffer,
> } jumps to the end of the buffer and { jumps to the beginning. Therefore, {
> should similarly jump to the beginning of the buffer when there is only one
> line.
>
> See also https://vi.stackexchange.com/q/43730 for related discussion.
>
> Version of Vim
>
> 8.2.2121

This bug is also in the oldest version of vim I have already
compiled, 7.2.330.

If I understand the original author's intent, then the following
patch to 9.0.2185 seems to fix it. I may have missed something, but
I ran "make test" before and after the fix and the same tests failed
both times, so this fix doesn't break anything being tested.

Regards,
Gary


diff --git a/src/textobject.c b/src/textobject.c
index b315d0320..d4380b7cf 100644
--- a/src/textobject.c
+++ b/src/textobject.c
@@ -226,7 +226,7 @@ findpar(
if (both && *ml_get(curr) == '}') // include line with '}'
++curr;
curwin->w_cursor.lnum = curr;
- if (curr == curbuf->b_ml.ml_line_count && what != '}')
+ if (curr == curbuf->b_ml.ml_line_count && what != '}' && dir > 0)
{
char_u *line = ml_get(curr);



Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/13780/1870165802@github.com>

Christian Brabandt

unread,
Dec 27, 2023, 1:16:15 PM12/27/23
to vim/vim, vim-dev ML, Comment

Closed #13780 as completed via 9e6549d.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/issue/13780/issue_event/11346565112@github.com>

Reply all
Reply to author
Forward
0 new messages