Hi,

On 3/6/07, Corinna Vinschen <[EMAIL PROTECTED]> wrote:
Hi,

I've searched for this for some time now but it's either not available
or I have to hone my search skills a lot.

Most of the time I have multiple xterms opened, running vim sessions
within the same project.  The files are tagged and I'm using :ta and :tj
a lot.  It happens often that I'm about to jump to a tagged function in
a file which I have opened in another xterm.  What happens is that the
swap file is found and the "Swap file [...] already exists" message is
printed, giving the usual choice which has to be confirmed.

The more often this happens, the more annoying it is.  What I usually
want is to open the file readonly, because I just want to have a look
into that function.  The actual editing of this file is done in the
other vim window.  I can't find a way to accomplish this.  I know
there's the shortmess=A option, but it avoids the attention message in a
dangerous way:  It doesn't print *any* warning and it allows to edit the
file.  If I really edit the file at this point, because I miss the fact
that this is the same file as in the other xterm session, the first
warning appears in the second session only when trying to write back the
changes made there.

So, the bottom line is, I'm looking for is a way to open a file
automatically in r/o mode if I'm going to jump to a tag in that file
and the file is opened in another session.

Is that possible already?  If not, would it make sense to add a setting
which enables this behaviour?


You can use the following autocmd (only in Vim7) to open a file
in read-only mode (if the file is already opened in another Vim instance)
while jumping to a tag in that file. In all other cases, you will be
prompted if the swap file already exists for that file.

autocmd SwapExists * if v:swapcommand =~ '^:ta\%[g] ' | let
v:swapchoice='o' | endif

- Yegappan

Reply via email to