Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand a symbolic link to the full path of a filename in vim?

Tags:

vim

I'm using a Mac and MacVim 7.3.

I have a symbolic link ~/some/symlink which is a link to a real file ~/some/actual_file.

When I "vim ~/some/symlink" it brings up the file in vim with vim's status line saying the name is ~/some/symlink, which makes sense.

How do I get the full path of the "real" file ~/some/actual_file from within vim? I want the vim status line to say ~/some/actual_file instead of ~/some/symlink.

I expected that the vim function resolve() would work, given its help description (pasted below), but resolve("~/some/symlink") returns ~/some/symlink, so that's no help.

What am I missing? Thanks!

resolve({filename})                 *resolve()* *E655*
        On MS-Windows, when {filename} is a shortcut (a .lnk file),
        returns the path the shortcut points to in a simplified form.
        On Unix, repeat resolving symbolic links in all path
        components of {filename} and return the simplified result.
        To cope with link cycles, resolving of symbolic links is
        stopped after 100 iterations.
        On other systems, return the simplified {filename}.
like image 747
svec Avatar asked Apr 26 '11 18:04

svec


People also ask

How do I get full path of file in Gvim?

If all that is wanted is to display the name of the current file, type Ctrl-G (or press 1 then Ctrl-G for the full path).

Does a symbolic link take up space?

Yes. They both take space as they both still have directory entries. A hardlink entry (really, a "normal entry" that [often] shares an inode) takes space, as does a symlink entry which must store the link path (the text itself) somehow.

How do I create a symbolic link to a file in Linux?

You use the ln command to create the links for the files and the -s option to specify that this will be a symbolic link. If you omit the -s option, then a hard link will be created instead. The existing_source_file represents the file on your computer that you want to create the symbolic link for.


1 Answers

Your problem is the "~", which isn't really part of the filename, but instead a shorthand for your home directory. You can use expand() and then resolve(). eg:

:echo resolve(expand("~/some/symlink"))

expand() will also expand things like environment variables (eg: $HOME, $VIMRUNTIME).

like image 71
Laurence Gonsalves Avatar answered Oct 03 '22 15:10

Laurence Gonsalves