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

Re: A challenge for those who feel like it

Expand Messages
  • A.J.Mechelynck
    ... I could write it if I needed it, but since you already have an answer I won t. :-þ Happy First of May. Best regards, Tony. -- Minnie Mouse is a slow maze
    Message 1 of 4 , Apr 27, 2007
    • 0 Attachment
      Dolazy wrote:
      > Yesterday I wanted to write a function for opening files that resembled the
      > Firefox feature of right clicking a link and choose 'Open link in new tab'.
      > With the difference that I would use a hotkey instead of the mouse.
      >
      > The requirements where this:
      > - open the file indicated by the filename under the cursor in a new tab
      > - the new tab had to be the last tab
      > - the new tab would be opened 'in background', in other words: the original
      > tab would remain active
      > - afterwards the cursor should go one line down, so that you can repeat the
      > command by pressing the same keystroke again
      >
      > How would this be done? (I found a solution yesterday, but I feel so proud
      > of it that I don't want to share it immediately and see what you would come
      > up with..)
      >
      > Happy Friday!
      >
      > Francis

      I could write it if I needed it, but since you already have an answer I won't. :-þ

      Happy First of May.

      Best regards,
      Tony.
      --
      Minnie Mouse is a slow maze learner.
    • Dave Land
      Francis, I took your challenge a long time ago, because I do the same thing: when I m editing JSP source code, I want to follow long chains of included files,
      Message 2 of 4 , Apr 27, 2007
      • 0 Attachment
        Francis,

        I took your challenge a long time ago, because I do the same thing:
        when I'm editing JSP source code, I want to follow long chains of
        included files, so I think I know just what you want...

        map <silent> <C-G> <C-W>gf:tabm 999<CR>

        It opens the file under the cursor in a new tab, then moves the tab
        to position 999, which is generally way after any tabs I have open, so
        it goes to the end.

        I use a Mac, so control-g is free for me. You can, of course, put it
        on whatever key makes you happy.

        Dave

        On Apr 27, 2007, at 4:57 AM, Dolazy wrote:

        >
        > Yesterday I wanted to write a function for opening files that
        > resembled the
        > Firefox feature of right clicking a link and choose 'Open link in
        > new tab'.
        > With the difference that I would use a hotkey instead of the mouse.
        >
        > The requirements where this:
        > - open the file indicated by the filename under the cursor in a new
        > tab
        > - the new tab had to be the last tab
        > - the new tab would be opened 'in background', in other words: the
        > original
        > tab would remain active
        > - afterwards the cursor should go one line down, so that you can
        > repeat the
        > command by pressing the same keystroke again
        >
        > How would this be done? (I found a solution yesterday, but I feel
        > so proud
        > of it that I don't want to share it immediately and see what you
        > would come
        > up with..)
        >
        > Happy Friday!
        >
        > Francis
        > --
        > View this message in context: http://www.nabble.com/A-challenge-for-
        > those-who-feel-like-it-tf3657250.html#a10217805
        > Sent from the Vim - General mailing list archive at Nabble.com.
        >
      • Ian Tegebo
        ... func! BgTab() Get the number of the active tab. let s:active = tabpagenr() Get file to open let s:newfile = expand( ) Go to last tab exe
        Message 3 of 4 , Apr 27, 2007
        • 0 Attachment
          On 4/27/07, Dave Land <land@...> wrote:
          > Francis,
          >
          > I took your challenge a long time ago, because I do the same thing:
          > when I'm editing JSP source code, I want to follow long chains of
          > included files, so I think I know just what you want...
          >
          > map <silent> <C-G> <C-W>gf:tabm 999<CR>
          >
          > It opens the file under the cursor in a new tab, then moves the tab
          > to position 999, which is generally way after any tabs I have open, so
          > it goes to the end.
          >
          > I use a Mac, so control-g is free for me. You can, of course, put it
          > on whatever key makes you happy.
          >
          > Dave
          >
          > On Apr 27, 2007, at 4:57 AM, Dolazy wrote:
          >
          > >
          > > Yesterday I wanted to write a function for opening files that
          > > resembled the
          > > Firefox feature of right clicking a link and choose 'Open link in
          > > new tab'.
          > > With the difference that I would use a hotkey instead of the mouse.
          > >
          > > The requirements where this:
          > > - open the file indicated by the filename under the cursor in a new
          > > tab
          > > - the new tab had to be the last tab
          > > - the new tab would be opened 'in background', in other words: the
          > > original
          > > tab would remain active
          > > - afterwards the cursor should go one line down, so that you can
          > > repeat the
          > > command by pressing the same keystroke again
          > >
          > > How would this be done? (I found a solution yesterday, but I feel
          > > so proud
          > > of it that I don't want to share it immediately and see what you
          > > would come
          > > up with..)
          > >
          > > Happy Friday!
          > >
          > > Francis
          > > --
          > > View this message in context: http://www.nabble.com/A-challenge-for-
          > > those-who-feel-like-it-tf3657250.html#a10217805
          > > Sent from the Vim - General mailing list archive at Nabble.com.
          > >
          >
          >
          Here's my version:

          ------------------------------------------------------------------------------
          func! BgTab()
          " Get the number of the active tab.
          let s:active = tabpagenr()

          " Get file to open
          let s:newfile = expand('<cWORD>')

          " Go to last tab
          exe ':tabl'

          " Open newfile in next tab
          exe ':tabnew '.s:newfile

          " Go back to original tab page and down one line
          exe ':tabnext '.s:active
          normal j
          endfunc

          map <silent> <C-G> <Esc>:call BgTab()<CR>
          ------------------------------------------------------------------------------

          For extra credit, if expand('<cWORD>') fails to find a valid file,
          perhaps this function could use the lookupfile script:

          http://www.vim.org/scripts/script.php?script_id=1581

          If not, perhaps at least findfile().

          --
          Ian Tegebo
        • Dolazy
          Thanks for your replies. I like the first solution, but it doesn t return to the original tab, which was what I found most difficult. Ian s solution works :-)
          Message 4 of 4 , May 2, 2007
          • 0 Attachment
            Thanks for your replies.

            I like the first solution, but it doesn't return to the original tab, which
            was what I found most difficult.
            Ian's solution works :-)

            I didn't know about the function tabpagenr(), my solution was:

            :function OpenFile()
            : let tab_id = expand("%")
            : tab split
            : tabmove
            : cs find f <cfile> " locate the file using cscope plugin ( 'normal gf'
            is fine also)
            : while tab_id != expand("%")
            : tabprev
            : endw
            : normal j
            :endfunction

            Kind regards,
            Francis
            --
            View this message in context: http://www.nabble.com/A-challenge-for-those-who-feel-like-it-tf3657250.html#a10281573
            Sent from the Vim - General mailing list archive at Nabble.com.
          Your message has been successfully submitted and would be delivered to recipients shortly.