How do I replicate vim settings across two machines?

27 views
Skip to first unread message

Ottavio Caruso

unread,
Mar 14, 2023, 7:01:44 AM3/14/23
to vim...@googlegroups.com
Hi,

I have two laptops.

LAP-EXT is a laptop that I use when out and about and is connected to
the Internet via mobile 4G.

I frequently edit a file called mlog.txt

$ vim ~/docs/mlog

At home I have another laptop (LAP-HOME), with no access to the
Internet, on which I mount $HOME on LAP1 over sshfs:


$ sshfs LAP-HOME: ~/external

Both machines run latest Debian stable.

So I can access mlog.txt as:

$ vim ~/external/docs/mlog


However if I do that, I get different behaviours, for example the cursor
mark is in different places, so I don't know where I left the text on
the other machine.

The only workaround at the moment is to ssh to LAP-EXT and run vim from
there.

How can I tell vim on LAP-HOME to use exactly the same settings as vim
on LAP-EXT including leaving the cursor at the same position?



--
Ottavio Caruso

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Christian Brabandt

unread,
Mar 14, 2023, 7:38:21 AM3/14/23
to vim...@googlegroups.com

On Di, 14 Mär 2023, 'Ottavio Caruso' via vim_use wrote:

> Hi,
>
> I have two laptops.
>
> LAP-EXT is a laptop that I use when out and about and is connected to the
> Internet via mobile 4G.
>
> I frequently edit a file called mlog.txt
>
> $ vim ~/docs/mlog
>
> At home I have another laptop (LAP-HOME), with no access to the Internet, on
> which I mount $HOME on LAP1 over sshfs:
>
>
> $ sshfs LAP-HOME: ~/external
>
> Both machines run latest Debian stable.
>
> So I can access mlog.txt as:
>
> $ vim ~/external/docs/mlog
>
>
> However if I do that, I get different behaviours, for example the cursor
> mark is in different places, so I don't know where I left the text on the
> other machine.
>
> The only workaround at the moment is to ssh to LAP-EXT and run vim from
> there.
>
> How can I tell vim on LAP-HOME to use exactly the same settings as vim on
> LAP-EXT including leaving the cursor at the same position?

You are editing the same file using 2 different paths, so Vim thinks
those are different files. I don't think there is a way to convince Vim
that those are the same files, thus the only other option would be to
edit your viminfo file manually and carefully and change the path there.

Best,
Christian
--
Eine Frau begeht einen Fehler, wenn sie den Mann schon beim ersten
Beisammensein ihre Blinddarm-Operationsnarbe bewundern läßt.
-- Cathérine Deneuve

Ottavio Caruso

unread,
Mar 14, 2023, 10:10:03 AM3/14/23
to vim...@googlegroups.com
Thanks.

Would it work if I sym-linked the remote .viminfo to the local one (or
vice versa)?

Enan Ajmain

unread,
Mar 14, 2023, 10:35:05 AM3/14/23
to 'Ottavio Caruso' via vim_use
On Tue, 14 Mar 2023 14:09:47 +0000
"'Ottavio Caruso' via vim_use" <vim...@googlegroups.com> wrote:
> Would it work if I sym-linked the remote .viminfo to the local one (or
> vice versa)?

First, you _have_ to do that. That's the way you share the info of
which line you closed a file on, etc. The problem Christian was talking
about was the difference in filenames of the same file. That question
comes _after_ you have made a shared .viminfo file (either by symlinking
or by using git).

Christian will be able to clarify better when they reply.

--
Enan
3nan....@gmail.com
https://www.github.com/3N4N

Gary Johnson

unread,
Mar 14, 2023, 1:19:31 PM3/14/23
to 'Ottavio Caruso' via vim_use
On 2023-03-14, Enan Ajmain wrote:
> On Tue, 14 Mar 2023 14:09:47 +0000
> "'Ottavio Caruso' via vim_use" <vim...@googlegroups.com> wrote:
> > Would it work if I sym-linked the remote .viminfo to the local one (or
> > vice versa)?
>
> First, you _have_ to do that. That's the way you share the info of
> which line you closed a file on, etc. The problem Christian was talking
> about was the difference in filenames of the same file. That question
> comes _after_ you have made a shared .viminfo file (either by symlinking
> or by using git).

You could instead have your vimrc test for the existence of
~/external/.viminfo (or any file or directory under ~/external when
mounted), and if it exists, set 'viminfofile' to
"~/external/.viminfo.

One solution to the problem of the file names being different would
be to pre-process the .viminfo file before it is read, replacing
$HOME/docs/mlog with $HOME/external/docs/mlog or vice versa,
depending on which laptop you are on, or perhaps on which file
exists. You could use a sed script with -i to do that, or use vim
to read, modify and write the .viminfo file. That would all be done
within your vimrc so that it is done automatically every time you
run vim. If the overhead of doing that is too great, you could, for
example, do that only when editing mlog.

Regards,
Gary

Ottavio Caruso

unread,
Mar 31, 2023, 5:23:12 AM3/31/23
to vim...@googlegroups.com
Follow up to this thread, see bottom post. I have been messing about
with vim and I have used this command from my local machine:

$ vim ~/external/docs/mlog -i ~/external/.viminfo

From the manual:

-i {viminfo}
Specifies the filename to use when reading or writing the
viminfo file, instead of the default "~/.viminfo". This
can also be used to skip the use of the .viminfo file, by
giving the name "NONE".


But when I use this syntax, the cursor mark is still not at the same
place where I left when I used vim directly on the remote machine.

So, my question is, what is the practical point of this switch?




-------- Weitergeleitete Nachricht --------
Betreff: Re: How do I replicate vim settings across two machines?
Datum: Tue, 14 Mar 2023 20:34:53 +0600
Von: Enan Ajmain <3nan....@gmail.com>
Antwort an: vim...@googlegroups.com
An: 'Ottavio Caruso' via vim_use <vim...@googlegroups.com>
Newsgruppen: gmane.editors.vim
Referenzen: <3578ec15-99a6-9fcc-1...@yahoo.com>
<3578ec15-99a6-9fcc...@yahoo.com>
<ZBBcopAm3aXJ/A...@256bit.org>
<885d99d6-60cc-d5ec...@yahoo.com>

Christian Brabandt

unread,
Mar 31, 2023, 10:40:51 AM3/31/23
to vim...@googlegroups.com

On Fr, 31 Mär 2023, 'Ottavio Caruso' via vim_use wrote:

> Follow up to this thread, see bottom post. I have been messing about with
> vim and I have used this command from my local machine:
>
> $ vim ~/external/docs/mlog -i ~/external/.viminfo
>
> From the manual:
>
> -i {viminfo}
> Specifies the filename to use when reading or writing the
> viminfo file, instead of the default "~/.viminfo". This
> can also be used to skip the use of the .viminfo file, by
> giving the name "NONE".
>
>
> But when I use this syntax, the cursor mark is still not at the same place
> where I left when I used vim directly on the remote machine.

I suppose because the filename is still stored twice within the viminfo
file with two different paths? Open your viminfo file (please make a
backup of it before messing with it) and search for the filename, for
which this issue occurs. You most likely find it there twice and you
need to make sure to have it there only once (with whatever path you
want to access the file).

> So, my question is, what is the practical point of this switch?

It uses a different viminfo file than the default one. By itself it
won't help, because you still have the problem, that you are editing the
same file under two different paths, so it looks like 2 different files
for Vim.

Best,
Christian
--
Die Religion hat viel Schlechtes und nur wenig Gutes hervorgebracht.
-- Claude Adrien Helvétius

K otgc

unread,
Mar 31, 2023, 8:10:15 PM3/31/23
to vim_use
I have nothing to add, but I like Christian's signature with varying quotes.  I might search how to do that too :-)  Catherine Deneuve was all class.

Ottavio Caruso

unread,
Apr 1, 2023, 6:01:42 AM4/1/23
to vim...@googlegroups.com
Ok, thanks. It makes sense.

Ottavio Caruso

unread,
Apr 1, 2023, 6:02:51 AM4/1/23
to vim...@googlegroups.com, K otgc
Am 01/04/2023 um 00:10 schrieb K otgc:
> I have nothing to add, but I like Christian's signature with varying
> quotes. I might search how to do that too

Fortune.
Reply all
Reply to author
Forward
0 new messages