Un-POSIX-like behavior of join command

45 views
Skip to first unread message

Brennan Vincent

unread,
Nov 12, 2019, 2:47:49 AM11/12/19
to v...@vim.org
When joining a line that is followed by an empty line (or one with only
spaces), POSIX specifies that it should be deleted without the current
line being affected. See the section "Join" in
https://pubs.opengroup.org/onlinepubs/9699919799/ .

However, vim appends a space to the current line in this case. For
example, if line 1 is "foo", and line 2 is blank, after executing :1j
line 1 will be "foo ", as can be seen by executing the following (`ex`
is provided by `vi` on my system)

$ echo -e 'foo\n' > test.txt && echo -e '1j\nwq' | ex test.txt && wc -c
test.txt
5 test.txt

nvi/nex give the POSIX behavior:

$ echo -e 'foo\n' > test.txt && echo -e '1j\nwq' | nex test.txt && wc -c
test.txt
4 test.txt

Is this a bug, or intentional?


Tony Mechelynck

unread,
Nov 12, 2019, 3:04:59 AM11/12/19
to vim_use, v...@vim.org
If you want Vim to behave as close as possible to "what Vi must do"
according to POSIX, you should set the $VIM_POSIX environment
variable: for instance (in a bash shell) by running Vim as

VIM_POSIX=1 vim -u NONE

Otherwise Vim will intentionaly deviate from some of the "rules" set
by POSIX. For details, see:
:help posix
:help 'cpoptions'
This latter one is quite long, check all flags other than aABceFs
including, but not limited to (at the bottom of the list) all POSIX
flags.

Best regards,
Tony.

Bram Moolenaar

unread,
Nov 12, 2019, 2:12:19 PM11/12/19
to vim...@googlegroups.com, Brennan Vincent, v...@vim.org
I can't think of a reason why it works this way. And the trailing space
is useless. So we should call it a bug.

What should happen if the second line is blank, not empty?

--
hundred-and-one symptoms of being an internet addict:
77. The phone company asks you to test drive their new PBX system

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Nov 12, 2019, 2:27:12 PM11/12/19
to vim...@googlegroups.com, Bram Moolenaar, Brennan Vincent, v...@vim.org

I wrote:

> Brennan Vincent wrote:
>
> > When joining a line that is followed by an empty line (or one with only
> > spaces), POSIX specifies that it should be deleted without the current
> > line being affected. See the section "Join" in
> > https://pubs.opengroup.org/onlinepubs/9699919799/ .
> >
> > However, vim appends a space to the current line in this case. For
> > example, if line 1 is "foo", and line 2 is blank, after executing :1j
> > line 1 will be "foo ", as can be seen by executing the following (`ex`
> > is provided by `vi` on my system)
> >
> > $ echo -e 'foo\n' > test.txt && echo -e '1j\nwq' | ex test.txt && wc -c
> > test.txt
> > 5 test.txt
> >
> > nvi/nex give the POSIX behavior:
> >
> > $ echo -e 'foo\n' > test.txt && echo -e '1j\nwq' | nex test.txt && wc -c
> > test.txt
> > 4 test.txt
> >
> > Is this a bug, or intentional?
>
> I can't think of a reason why it works this way. And the trailing space
> is useless. So we should call it a bug.
>
> What should happen if the second line is blank, not empty?

The spec apparently says that blank lines are also not resulting in a
trailing space:

1. Discard leading <space> characters from the line to be joined.
2. If the line to be joined is now empty, delete it, and skip steps 3 through 5.

--
hundred-and-one symptoms of being an internet addict:
78. You find yourself dialing IP numbers on the phone.

Brennan Vincent

unread,
Nov 12, 2019, 6:08:06 PM11/12/19
to Bram Moolenaar, vim...@googlegroups.com, v...@vim.org, antoine.m...@gmail.com
Tony: Thanks for the tip. I have tried with `VIM_POSIX=1 vim -u NONE` and I get the same undocumented un-POSIX-like behavior.

Bram: Thanks for confirming. If we are agreed that this is a bug, is there some Vim bug tracker I should enter it on?

Tony Mechelynck

unread,
Nov 12, 2019, 7:17:33 PM11/12/19
to vim_use, Bram Moolenaar, v...@vim.org
On Wed, Nov 13, 2019 at 12:08 AM Brennan Vincent <bre...@umanwizard.com> wrote:
>
>
>
> On Nov 12, 2019, at 2:26 PM, Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> I wrote:
>
> Brennan Vincent wrote:
>
> When joining a line that is followed by an empty line (or one with only
> spaces), POSIX specifies that it should be deleted without the current Ligne des Fagnes
Now that Bram is aware of the problem, and regards it as a bug, IMHO
we can expect a fix in a few days. If no patch concerning it appears
in a week or two you could open an "issue" on Vim's github site to
make sure it doesn't fall off the radar. But it is quite possible that
the problem will get fixed with no further action on your part.

Best regards,
Tony.

Tony Mechelynck

unread,
Nov 12, 2019, 7:20:03 PM11/12/19
to vim_use, Bram Moolenaar, v...@vim.org
P.S.
:s/Ligne des Fagnes//
(spurious paste from my clipboard)

Best regards,
Tony.

Tony Mechelynck

unread,
Nov 12, 2019, 8:20:05 PM11/12/19
to vim_use, Bram Moolenaar, v...@vim.org
P.P.S. It is _already_ fixed (patch 8.1.2293).

Best regards,
Tony.

Brennan Vincent

unread,
Nov 13, 2019, 12:42:10 PM11/13/19
to vim...@googlegroups.com, Bram Moolenaar, v...@vim.org
This is great, issue fixed by project BDFL within a few hours of reporting.

As a token of thanks I have sent a donation to ICCF.
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXtAm5qooCd%3DUsv_yqykzD1Oot%3DDBCJqhqXV4kFGdtBUFA%40mail.gmail.com.


Reply all
Reply to author
Forward
0 new messages