using "gf" or "^Wf" with symlinked files?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

using "gf" or "^Wf" with symlinked files?

Tim Chase
Discovered today that the following doesn't do what I hoped (though I
can understand why).  To demonstrate

  $ mkdir a b
  $ cd a
  $ echo hello > included.txt
  $ echo include included.txt > including.txt
  $ cd ../b
  $ ln -s ../a/including.txt include_in_b.txt
  $ vim include_in_b.txt

Now putting the cursor on "included.txt" in the file and using either
is unable to find the target/included file because the linked file is
actually in a remote folder.  Of course, doing

  $ cd ../a
  $ vim including.txt

or

  :cd ../a

inside vim works as expected, letting me use "gf" and friends to jump
to the included files without issue.

Is there a simple way to get "gf"/"^Wf" (and any others in the same
family of functions) to chase the link to find the corresponding file
as if that target's directory was in 'path'?

Thanks!

-tim


(the actual context is a remind(1) reminder file where ~/.reminders
is a link to ~/.config/remind/reminders.rem which includes each of my
individual calendar files are in that ~/.config/remind/ directory, so
editing ~/.reminders doesn't give me quick access to the per-calendar
subfiles that get included if I use "gf" and friends)







--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: using "gf" or "^Wf" with symlinked files?

Matt Ackeret
dumb suggestion on my part - use a hard link instead of a soft link?

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: using "gf" or "^Wf" with symlinked files?

Tim Chase
On 2018-11-05 10:36, Matt Ackeret wrote:
> dumb suggestion on my part - use a hard link instead of a soft link?

Neither hard- nor sym- link makes a difference.  At least in the case
of the symlink, vim has a hope of knowing where the destination
directory is, whereas with a hard link, it would have to scavenge the
file-system for other directories containing the same inode#.

That said, I tend to default to symlinks unless I have a compelling
reason to do otherwise.  Fewer surprises when things cross
file-system boundaries.

-tim


--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: using "gf" or "^Wf" with symlinked files?

Eli the Bearded
In reply to this post by Tim Chase
Tim Chase <[hidden email]> wrote:
> (the actual context is a remind(1) reminder file where ~/.reminders
> is a link to ~/.config/remind/reminders.rem which includes each of my
> individual calendar files are in that ~/.config/remind/ directory, so
> editing ~/.reminders doesn't give me quick access to the per-calendar
> subfiles that get included if I use "gf" and friends)

Can you have all of these include a path?

   include ~/.config/remind/this
or
   include $HOME/.config/remind/that

Do you actually need ~/.reminders for something, or it that just
your editing short cut? Because I'd use an env variable instead of
a symlink myself. "export REMINDERS=$HOME/.config/remind/reminders.rem"
"vi $REMINDERS"

I ask because noticing a filename is a symlink and then doing things
differently based on that seems like it will have a lot of unexpected
effects for a lot of other people.

Elijah

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: using "gf" or "^Wf" with symlinked files?

Tim Chase
On 2018-11-05 15:09, Eli the Bearded wrote:

> Tim Chase <[hidden email]> wrote:
> > (the actual context is a remind(1) reminder file where
> > ~/.reminders is a link to ~/.config/remind/reminders.rem which
> > includes each of my individual calendar files are in that
> > ~/.config/remind/ directory, so editing ~/.reminders doesn't give
> > me quick access to the per-calendar subfiles that get included if
> > I use "gf" and friends)  
>
> Can you have all of these include a path?
>
>    include ~/.config/remind/this
> or
>    include $HOME/.config/remind/that

I suppose I could either include it in my path, but was hoping to
keep that uncluttered (and have a more generic symlink-chasing
solution).  Something could be hacked with a file-type trigger?

> Do you actually need ~/.reminders for something, or it that just
> your editing short cut?

remind(1)'s "rem" command looks for ~/.reminders by default.  If
you've not used it, `remind` is a bit like calendar(1) (or google
calendar, or calcurse, etc) on steroids.

-tim



--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Solved] using "gf" or "^Wf" with symlinked files

Tim Chase
In reply to this post by Tim Chase
On 2018-11-05 10:02, Tim Chase wrote:
> $ mkdir a b
> $ cd a
> $ echo hello > included.txt
> $ echo include included.txt > including.txt
> $ cd ../b
> $ ln -s ../a/including.txt include_in_b.txt
> $ vim include_in_b.txt

I think I've found a workable solution:

  :set includeexpr=fnamemodify(resolve(@%),':p:h').'/'.v:fname


The trick was learning about three new (to me) things:

1) resolve() chases links as I needed

2) fnamemodify() is the generic way to transform what I'd previously
done only in expand() calls (e.g. "expand('%:p:h')")

3) 'includeexpr' and its "v:fname" are the trigger/glue holding the
whole thing together

So, despite using vim for about two decades, I'm still learning new
tricks.

Hopefully someone else finds this helpful too.

-tim



--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.