Triplicate text after mix-matching vim and nvi

33 views
Skip to first unread message

Ottavio Caruso

unread,
Feb 4, 2020, 4:04:26 AM2/4/20
to v...@vim.org
Hi,

Maybe this is off-topic but I hope you guys can help, as there's no
specific maling list for classic vi/nvi.

On my system (Linux/amd64 Debian 4.9.189) I have:

- vim (vim 8.1)
- vi (aliased to vim)
- nvi (nvi-1.81.6nb5 )

For self-educational purposes, I've been trying to teach myself to use
both vim and nvi, as I'm studying for a BSD-related certification,
where old vi is installed by default. So, to a certain extent, I am
looking for trouble, however...

I have a file (man-pages.txt) where I have a list of man pages that I
need to expand, for example:

man 8 tcpdump
man 1 login
man 8 sysctl
man 8 adduser
man 5 adduser.conf
man 8 rmuser
man 8 useradd
man 8 userdel

and so on. When I am finished with reading a man page, I cut the first
line and I paste to the last line, so:

1) dd
2) [shift] + g
3) p

And I've been doing this for a few months. Sometimes I use vim and
some other times nvi.

At one point, I noticed that the size of this file was growing
abnormally. Then, I realised that the entries were in duplicate or
triplicate copies, that is, as if I had copied the whole file and then
pasted it twice onto itself.

I removed the duplicate lines and started from scratch and, as a proof
of concept, alternated between vim and nvi, just to see if this would
happen again, and indeed it did.

I wonder if somebody has a clue why this happens. Is this something I
should expect? Is there a markup that one editor places that confuses
the other?

Thanks

--
Ottavio Caruso

Tony Mechelynck

unread,
Feb 4, 2020, 8:27:20 AM2/4/20
to vim_use
The following mapping will move the first line from top to bottom of
the file (at least in Vim in 'nocompatible' mode, I'm not sure about
vi (or 'compatible' Vim) and nvi):

:map <F5> :1d<Bar>$put<CR>

(<Bar> rather than | to avoid interpreting the rest when declaring the
mapping rather than when executing it). Of course you can use any
convenirnt {lhs} instead of <F5>

Best regards,
Tony.

Christian Brabandt

unread,
Feb 4, 2020, 8:43:45 AM2/4/20
to v...@vim.org
Not sure what could be causing this. Note however, you can use the
`:copy` or `:t` alias. So to copy the first line to the last line, you
can simply do:

:1t$

Best,
Christian
--
Man muß wissen, daß der Krieg etwas Allgemeines ist, daß das Recht
auf dem Streit beruht und daß alles aus dem Streit und aus der
Notwendigkeit entsteht.
-- Heraklit von Ephesus (540-480 v. Chr.)

Tim Chase

unread,
Feb 4, 2020, 8:52:52 AM2/4/20
to Tony Mechelynck, vim...@googlegroups.com
On 2020-02-04 14:27, Tony Mechelynck wrote:
> The following mapping will move the first line from top to bottom of
> the file (at least in Vim in 'nocompatible' mode, I'm not sure about
> vi (or 'compatible' Vim) and nvi):
>
> :map <F5> :1d<Bar>$put<CR>

Or more simply

:map <f5> :1m$<cr>

Should work in vi, vim, nvi, neovim, and the same concept/command in
ed(1). It should also work regardless of your 'compatible' settings.
:-)

(within vim/neovim, I'd tend to use "nnoremap" instead of just "map")

-tim


Tim Chase

unread,
Feb 4, 2020, 9:05:13 AM2/4/20
to vim...@googlegroups.com
On 2020-02-04 14:43, Christian Brabandt wrote:
> On Di, 04 Feb 2020, 'Ottavio Caruso' via vim_use wrote:
> > 1) dd
> > 2) [shift] + g
> > 3) p
>
> :1t$

That copies where Ottavio's command sequence moves, so he'd want

:1m$

:-)

-tim

Christian Brabandt

unread,
Feb 4, 2020, 9:10:21 AM2/4/20
to vim...@googlegroups.com
Oh, yes he wanted to move and not copy. Sorry.

Best,
Christian
--
Es gibt Menschen, denen jedes Lob Tadel ist, das nicht das größte ist.
-- Jean Paul

Tim Chase

unread,
Feb 4, 2020, 9:39:42 AM2/4/20
to 'Ottavio Caruso' via vim_use, v...@vim.org
On 2020-02-04 09:03, 'Ottavio Caruso' via vim_use wrote:
> I have a file (man-pages.txt) where I have a list of man pages that
> I need to expand, for example:
>
> man 8 tcpdump
> man 1 login
> man 8 sysctl
> man 8 adduser
> man 5 adduser.conf
> man 8 rmuser
> man 8 useradd
> man 8 userdel

While I suggested using ":1m$" elsewhere in the thread, I'm glad I'm
not the only one doing something similar with man-pages.

However, I've used calendar programs to do this. You can either use
the venerable calendar(1) format:

# BSD date(1)
$ d=$(date +%s); while read line ; do printf '%s\t%s\n' $(date
-r $d +%Y-%m-%d ) "$line" ; d=$(( $d + (60*60*24) )); done <
list_of_manpages.txt >> ~/.calendar

# Linux date(1)
$ d=$(date +%s) ; while read line ; do printf '%s\t%s\n'
$(date --date="@$d" +%Y-%m-%d) "$line" ; d=$(( $d + (60*60*24) )) ;
done < list_of_manpages.txt >> ~/.calendar

(though beware that, if you have more than 365 entries, calendar(1)
seems to ignore the year)

You can then invoke

$ calendar

(or put it in a cron-job if it's not automatically picked up by your
system scripts)

I do something similar using remind(1) which I prefer for calendaring:

$ cat remify_manpages.awk
BEGIN {
print "SET ManStart date(2020,1,5)"
}
$7 ~ /^[1678]$/ {
printf("REM [ManStart + %i] MSG man %s %%\"%s%%\"%%\n", NR - 1, $7,
$6)
}

$ find /usr/share/man/man[1678]/ -maxdepth 2 -type f |
grep -vi perl |
sort -R |
awk -F'[./]' -f remify_manpages.awk > manpages.rem

(I ignore the perl man-pages and randomly shuffle them)

and then invoking remind(1) will include my man-page-of-the-day for
that given date.

-tim




Ottavio Caruso

unread,
Feb 5, 2020, 3:34:57 AM2/5/20
to vim...@googlegroups.com
On Tue, 4 Feb 2020 at 13:27, Tony Mechelynck
<antoine.m...@gmail.com> wrote:

> The following mapping will move the first line from top to bottom of
> the file (at least in Vim in 'nocompatible' mode, I'm not sure about
> vi (or 'compatible' Vim) and nvi):
>
> :map <F5> :1d<Bar>$put<CR>
>
> (<Bar> rather than | to avoid interpreting the rest when declaring the
> mapping rather than when executing it). Of course you can use any
> convenirnt {lhs} instead of <F5>
>

Thanks. The remap works in vim but not in vi, probably because I'm
using the wrong syntax.

--
Ottavio Caruso

Ottavio Caruso

unread,
Feb 5, 2020, 3:39:26 AM2/5/20
to vim...@googlegroups.com
On Tue, 4 Feb 2020 at 14:10, Christian Brabandt <cbl...@256bit.org> wrote:
>
>
> On Di, 04 Feb 2020, Tim Chase wrote:
>
> > On 2020-02-04 14:43, Christian Brabandt wrote:
> > > On Di, 04 Feb 2020, 'Ottavio Caruso' via vim_use wrote:
> > > > 1) dd
> > > > 2) [shift] + g
> > > > 3) p
> > >
> > > :1t$
> >
> > That copies where Ottavio's command sequence moves, so he'd want
> >
> > :1m$
> >
>
> Oh, yes he wanted to move and not copy. Sorry.

Tim & Christian,

the command works in both vim and nvi. The remap only in vim. I'll try
to find a way of making it work in nvi, but this would be off topic.

(BTW: if anybody knows a of a vi/nvi mailing list or usenet group,
please let me know, on of off list)

--
Ottavio Caruso

Ottavio Caruso

unread,
Feb 5, 2020, 3:59:33 AM2/5/20
to vim...@googlegroups.com
On Wed, 5 Feb 2020 at 08:38, Ottavio Caruso
<ottavio2006...@yahoo.com> wrote:
>
> On Tue, 4 Feb 2020 at 14:10, Christian Brabandt <cbl...@256bit.org> wrote:
> >
> >
> > On Di, 04 Feb 2020, Tim Chase wrote:
> >
> > > On 2020-02-04 14:43, Christian Brabandt wrote:
> > > > On Di, 04 Feb 2020, 'Ottavio Caruso' via vim_use wrote:
> > > > > 1) dd
> > > > > 2) [shift] + g
> > > > > 3) p
> > > >
> > > > :1t$
> > >
> > > That copies where Ottavio's command sequence moves, so he'd want
> > >
> > > :1m$
> > >
> >
> > Oh, yes he wanted to move and not copy. Sorry.
>
> Tim & Christian,
>
> the command works in both vim and nvi. The remap only in vim. I'll try
> to find a way of making it work in nvi, but this would be off topic.

Correction: I had to prefix the maps with [ctrl]+v and now it works on nvi too:

nvi:
map ^[[15~ :1m$^M

vim:
map <f5> :1m$<cr>

Thanks Tony, Christian and Tim!


--
Ottavio Caruso

Tim Chase

unread,
Feb 5, 2020, 8:23:01 AM2/5/20
to vim...@googlegroups.com
On 2020-02-05 08:38, 'Ottavio Caruso' via vim_use wrote:
> the command works in both vim and nvi. The remap only in vim. I'll
> try to find a way of making it work in nvi, but this would be off
> topic.

Ah, good point. The "<f5>" notation is a vim thing. You can either
use some other key such as "Q"

:map Q :1m$^M

where ^M is entered using control+V followed by control+M

(just tested in the nvi that I have here on FreeBSD)

Alternatively, if you know the escape sequence for the key you want
such as F5, you might be able to enter it literally, escaping with
control+V as above.

(as I type this, your follow-up email arrived where you do just that)

> (BTW: if anybody knows a of a vi/nvi mailing list or usenet group,
> please let me know, on of off list)

I think this list is the closest there is. I regularly use vi/nvi,
vim, and ed(1), and occasionally neovim. I'm sure there are others.
There's enough overlap between vi/nvi and vim/neovim that even if
you're asking questions about vi/nvi here, you'll hopefully get some
good answers. It also helps get relevant answers if you mention that
your question is about vi/nvi instead of vim, so folks don't try to
reply with vim-specific answers.

-tim


Ottavio Caruso

unread,
Feb 10, 2020, 7:41:54 AM2/10/20
to v...@vim.org
On Tue, 4 Feb 2020 at 09:03, Ottavio Caruso
<ottavio2006...@yahoo.com> wrote:
>
>
> At one point, I noticed that the size of this file was growing
> abnormally. Then, I realised that the entries were in duplicate or
> triplicate copies, that is, as if I had copied the whole file and then
> pasted it twice onto itself.
>
> I removed the duplicate lines and started from scratch and, as a proof
> of concept, alternated between vim and nvi, just to see if this would
> happen again, and indeed it did.
>
> I wonder if somebody has a clue why this happens. Is this something I
> should expect? Is there a markup that one editor places that confuses
> the other?

For the record, the culprit is nvi (and mate-terminal).

When mate-terminal crashes (and this should not happen) obviously also
nvi crashes. For some reason, nvi creates multiple recovery files in
/tmp (and this shouldn't happen either).

So, for the time being, I have abandoned my educational purposes and
will stick with vim.

Thanks for making a great editor.


--
Ottavio Caruso
Reply all
Reply to author
Forward
0 new messages