Loading ...
Sorry, an error occurred while loading the content.

Jump to tag in a file opened in another session

Expand Messages
  • Corinna Vinschen
    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
    Message 1 of 6 , Mar 6, 2007
    • 0 Attachment
      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?


      Thanks in advance,
      Corinna

      --
      Corinna Vinschen
      Cygwin Project Co-Leader
      Red Hat
    • Zdenek Sekera
      ... My frequent problem as well and I also didn t find a way how to do it. Your suggestion seems to me very useful and practical, so if it cannot be done now,
      Message 2 of 6 , Mar 6, 2007
      • 0 Attachment
        > -----Original Message-----
        > From: Corinna Vinschen [mailto:vinschen@...]
        > Sent: 06 March 2007 10:21
        > To: vim-dev@...
        > Subject: Jump to tag in a file opened in another session
        >
        > 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?
        >

        My frequent problem as well and I also didn't find a way how
        to do it. Your suggestion seems to me very useful and practical,
        so if it cannot be done now, an addition you suggested would
        be extremely useful.


        ---Zdenek
      • Milan Vancura
        ... hi, I ve thought about the same feature. I think there are three solutions now: 1. use one xterm with tabs instead of several xterms (don t like) 2. use a
        Message 3 of 6 , Mar 6, 2007
        • 0 Attachment
          > 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.

          hi,

          I've thought about the same feature. I think there are three solutions now:

          1. use one xterm with tabs instead of several xterms
          (don't like)

          2. use a communication with vim server to synchronize
          (seems hard for me)

          3. write a couple of functions:

          tagjump - set the variable "jumpingThereBecauseOfTag" and calls tag jump
          checktag - check the variable "jumpingThereBecauseOfTag" and set readonly if
          this variable is set and swap file exists

          then create (and use) a new command :Tj calling tagjump and add an
          autocommand for BufReadPre event calling checktag

          It's just an idea, I still didn't write these. But I think it should work.


          Milan
        • Corinna Vinschen
          ... I guess the most easy way to accomplish this is another shortmess option which is like A, but with an automatic r/o open mode. If this behaviour is
          Message 4 of 6 , Mar 6, 2007
          • 0 Attachment
            On Mar 6 11:54, Milan Vancura wrote:
            > > 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.
            >
            > hi,
            >
            > I've thought about the same feature. I think there are three solutions now:
            >
            > 1. use one xterm with tabs instead of several xterms
            > (don't like)
            >
            > 2. use a communication with vim server to synchronize
            > (seems hard for me)
            >
            > 3. write a couple of functions:
            >
            > tagjump - set the variable "jumpingThereBecauseOfTag" and calls tag jump
            > checktag - check the variable "jumpingThereBecauseOfTag" and set readonly if
            > this variable is set and swap file exists
            >
            > then create (and use) a new command :Tj calling tagjump and add an
            > autocommand for BufReadPre event calling checktag
            >
            > It's just an idea, I still didn't write these. But I think it should work.

            I guess the most easy way to accomplish this is another shortmess option
            which is like A, but with an automatic r/o open mode. If this behaviour
            is accompanied with an inverse [readonly] marker (inverse red on color
            terminals), that would be sufficient, IMHO. Actually, if I have a file
            already open in another session I never want to open it for editing in
            another session. I'm aware that I'd have to use the -r option to
            recover, should that be necessary.


            Corinna

            --
            Corinna Vinschen
            Cygwin Project Co-Leader
            Red Hat
          • Yegappan Lakshmanan
            Hi, ... 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
            Message 5 of 6 , Mar 6, 2007
            • 0 Attachment
              Hi,

              On 3/6/07, Corinna Vinschen <vinschen@...> 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
            • Corinna Vinschen
              ... Thank you, that helps a lot! Corinna -- Corinna Vinschen Cygwin Project Co-Leader Red Hat
              Message 6 of 6 , Mar 7, 2007
              • 0 Attachment
                On Mar 6 12:42, Yegappan Lakshmanan wrote:
                > On 3/6/07, Corinna Vinschen <vinschen@...> wrote:
                > >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.
                >
                > 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

                Thank you, that helps a lot!


                Corinna

                --
                Corinna Vinschen
                Cygwin Project Co-Leader
                Red Hat
              Your message has been successfully submitted and would be delivered to recipients shortly.