On 4/27/07, Dave Land <[EMAIL PROTECTED]> 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

Reply via email to