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

Re: gf and new tab

Expand Messages
  • Dave Land
    ... I have mapped to open the file under the cursor in a new tab, and to make that tab the right-most tab (like the default behavior of some Web
    Message 1 of 4 , Jun 1, 2011
    • 0 Attachment
      On May 31, 2011, at 11:34 PM, Jürgen Krämer wrote:

      > eNG1Ne wrote:
      >
      >> Chuffed at remembering, after seeing it go past in the group, that gf
      >> opens the file under the cursor … less chuffed that when I use gf to
      >> check an include file, this closes the file I'm currently working on
      >> :-{ Any workarounds out there?
      >
      > there are also <Ctrl-W><f>, which opens the file under the cursor in a
      > new window, and <Ctrl-W><g><f>, which opens it in a new tab.

      I have <Ctrl-G> mapped to open the file under the cursor in a new tab,
      and to make that tab the right-most tab (like the default behavior of
      some Web browsers when opening a new tab):

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

      gf is highly extensible, by the way, through a combination of the path,
      suffixesadd and includeexpr options, which affect how Vim goes about
      turning "the name under the cursor" into a file reference.

      path is rather obvious: the first thing Vim does is to search through
      the items in your path option to see if there's a file with the name
      under the cursor.

      suffixesadd complements path by filling in the "other end" of the file
      name. It contains a comma-separated list of filename suffixes that Vim
      appends to the name under the cursor in search of a matching file. If
      you have "suffixesadd=.java,.jsp,.txt", and the word "Archive" is under
      the cursor, then Vim will search each spot in your path option for
      "Archive.java", "Archive.jsp", and "Archive.txt".

      includeexpr can be defined as a function on v:fname (the file under the
      cursor) to turn (for example) a relative path into an absolute path, to
      modify the path, or whatever other mischief you might want to get up to.

      With a co-worker, I crafted a function that handled our rather byzantine
      source code layout, and even turning Java import strings like
      "com.foo.bar.Archive" into the appropriate path, e.g.,
      "/code/base/src/com/foo/bar/Archive.java". Truly remarkable is the
      flexibility and extensibility of Vim.

      Having said all that, sadly, there's not a lot of good documentation on
      how to use includeexpr with gf, and it's quite difficult to debug,
      because it all happens "behind the scenes". With judicious use of echo
      (the oldest debugging trick in the book: dump to screen), you can do
      some pretty amazing stuff. I wish I had the time to fully document my
      50-odd-line function, but even then, I'd have to document our source
      code layout to make any sense of it, so I guess "proof of this theorem
      is left to the student as an exercise".

      I found some discussion of this topic on this very list from about a
      year ago that may be of interest:

      http://groups.google.com/group/vim_use/browse_thread/thread/ad2281a4d419814b/18b6c804706cf0c8?lnk=gst&q=includeexpr+gf#18b6c804706cf0c8

      Dave

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.