Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyper link for openning local file in Windows System #71

Closed
llinfeng opened this issue Sep 9, 2014 · 18 comments
Closed

Hyper link for openning local file in Windows System #71

llinfeng opened this issue Sep 9, 2014 · 18 comments

Comments

@llinfeng
Copy link

@llinfeng llinfeng commented Sep 9, 2014

It struck me this morning that Vimwiki could be turned into a real knowledge base if it could conduct the action of opening files from local directory.

The ideal thing would be to enable opening of directory and files by a string of directory. For those without file extension, we open it up as a directory (i.e. opening a new folder); for those with certain file extension, we open it up using the default setting by the operating system. [["Directory"]] might be a reasonable syntax for this purpose.

I wish this would be doable.

All the best,

-Linfeng

@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Sep 9, 2014

It struck me this morning that Vimwiki could be turned into a real knowledge base

That's the purpose ;)

I hope I can strike you with the information that this is already possible. Have a look at :h vimwiki-syntax-schemes. What you want is the local: or file: scheme.

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Sep 9, 2014

Great to know that this had been already implemented. Thanks for pointing out the available source.

However, I did not find a way to let Vimwiki know that I am using a windows machine and therefore the format of absolute path would be different (i.e. not starting with ///). What should the syntax be if I want to open the following:

directory: "C:\Users\llinfeng\Dropbox\Wiki\Freemind"
file: "C:\Users\llinfeng\Dropbox\Wiki\FreemindMy Wiki.mm"

I tried [[local:C:\Users\llinfeng\Dropbox\Wiki\Freemind]], but it did not work. Neither would [[file:C:\Users\llinfeng\Dropbox\Wiki\FreemindMy Wiki.mm]] work on my Windows machine.

Lastly, are spaces permitted in the directory?

All the best,

  • Linfeng

@llinfeng llinfeng changed the title Feature Request: Hyper link for openning local file? Hyper link for openning local file in Windows System Sep 9, 2014
@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Sep 11, 2014

I can't really test this issue, because I have only limited access to a windows machine, but I noticed that a backslash is apparently not allowed in links. Does [[file:C:/Users/...]] work, i.e. slashes instead of backslashes?

@lervag
Copy link
Contributor

@lervag lervag commented Sep 11, 2014

Great, thanks! This fixes the problem on my end.

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Sep 11, 2014

Yes, the fix had been testified to work well.

Here is what I found that is handy to do the conversion: http://vim.wikia.com/wiki/Change_between_backslash_and_forward_slash

I used the version with the "ToggleSlash" function.

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Sep 11, 2014

Reporting another issue:

While the file: handler works as expected, local: is not working well. It can only open directories that are children to the location in which the index file for the wiki is stored.

@llinfeng llinfeng reopened this Sep 11, 2014
@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Nov 24, 2014

@llinfeng: a link like [[local:../bla.txt]] works for me, also on Windows. What does the link you tried look like exactly?

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Dec 1, 2014

@EinfachToll: thank you for pointing to the ../ operator. I can now go out of base folder of vimwiki and navigate the other directories. With local:, now I can go to literally any directory within the same disk. However, given the caveat to be discussed below, I cannot go to other "disks", i.e. other partition of the hard disk. (Maybe this is only for Windows OS).

The restriction: I cannot use local with absolute path, by which I mean:

[[local:"C:/Users/llinfeng/Dropbox"]]

Nor would the following work (without the double quotes)

[[local:C:/Users/llinfeng/Dropbox/]]

Is there a way to "call the absolute path" of a directory? I thinks this will improve the functionality of Vimwiki by a great extent. This is not a problem with the file: syntax, which is intended to open a file. Given this, would it be possible to tune local: to behave in similar way as file:.

(For file:, I've tested that it won't work unless the "address" is appended by a file extension.)

Thanks again.

@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Dec 2, 2014

local: is for relative paths (i.e. relative to the directory containing the current file), file: is for absolute paths. Apart from that, they should behave the same.
So you want to go to arbitrary directories. But since Vim is a text editor, what should happen when you open a directory? Do you want Netrw to be called? (This is like typing :Explore)

@lervag
Copy link
Contributor

@lervag lervag commented Dec 2, 2014

I don't understand why one needs to have two labels for files. That is, it seems trivial to me to distinguish a relative and an absolute path, so why would you need a label to distinguish this?

@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Dec 2, 2014

You're right. It wasn't my idea ;)

@lervag
Copy link
Contributor

@lervag lervag commented Dec 2, 2014

Haha, ok. :)

@linuxcaffe
Copy link

@linuxcaffe linuxcaffe commented Dec 2, 2014

@einfach; thanks for that clarification of local: vs. file: and :Explore is
an interesting idea!

On 2 December 2014 at 03:41, Karl Yngve Lervåg notifications@github.com
wrote:

Haha, ok. :)

Reply to this email directly or view it on GitHub
#71 (comment).

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Dec 6, 2014

@EinfachToll, thank you for clarifying the usage for local and file. What I was trying to ask is how to open a directory through the explorer, by pressing <cr> on a link stored in Vimwiki. As folders are stored in hierarchy, and the idea of maintaining a Wiki is to crush the hierarchy in knowledge space and free the mind thereby, I think being able to manage (or simply get access to) the directory in a wiki way would be helpful.

:Explore is a good built-in function to Vim, but it is a command line option and costs key strokes. Is it possible to create hyperlinks in Vimwiki that could invoke a directory through absolute path? By invoke, I mean either open the directory through the explorer, or initiate a "explore" view in Vim (same as `:Explore').

Thanks again,

@EinfachToll
Copy link
Member

@EinfachToll EinfachToll commented Dec 11, 2014

Since not everybody has the netrw plugin loaded (me, for example) and this is a rather special demand, I think we leave this functionality to an extra function which the users can write themselves (see :h VimwikiLinkHandler). Put this in your vimrc:

function! VimwikiLinkHandler(link)
    let link = a:link
    if link =~ '^local:.*/'
        let local_dir = matchstr(link, '^local:\zs.*')
        let abs_dir = expand('%:p:h').'/'.local_dir
        " open dolphin in the desired directory. Sorry, I don't know how to open Windows explorer
        call system("dolphin " . shellescape(abs_dir) . " &")
        return 1
    elseif link =~ '^file:.*/'
        let dir = matchstr(link, '^file:\zs.*')
        " open the directory with netrw
        exe "Texplore " . dir
        return 1
    else
        return 0
    endif
endfunction

@llinfeng
Copy link
Author

@llinfeng llinfeng commented Dec 11, 2014

The function does not work so well. Thank you though. Found:

  1. file: will open NERDTree at the root, for some unknown reason.
  2. local: is still not opening a new directory.

However, please ignore my request. The relative path worked greatly and I am absolutely satisfied.

I appreciate your time and great help.

@jon-yip
Copy link

@jon-yip jon-yip commented May 11, 2015

Firstly I would like to thank you for this amazing plugin.
However, I've been trying to do something like [[~/playground/mycodes/]] to open a directory but instead of opening the directory vimwiki keeps asking me if I want to create a new directory under the current ~/vimwiki directory. Also I tried to use [[file:]] and [[local:]] to access other local files without success.
Have I missed something here?

P.S. I'm using OS X Yosemite.

@severoraz
Copy link

@severoraz severoraz commented May 21, 2019

Here is a modified version of the script that works for me. The other suggestions didn't.
This script opens all files with explorer.exe, which results in

  • for directories, opening them in explorer.exe
  • for files, opening them with their assigned application (system default)
function! VimwikiLinkHandler(link)
    let link = a:link
    let islink = 0
    if link =~ '^local:.*'
        let islink = 1
        let local_dir = matchstr(link, '^local:\zs.*')
        let abs_dir = expand('%:p:h').'/'.local_dir
        " open dolphin in the desired directory. Sorry, I don't know how to open Windows explorer
        " call system("cmd " . shellescape(abs_dir) . " &")
        " exe "!explorer '" . substitute(abs_dir,"/","\\\\",'g') . "'"
        " return 1
    elseif link =~ '^file:.*'
        let islink = 1
        let abs_dir = matchstr(link, '^file:\zs.*')
        " open the directory with netrw
        " call system("cmd " . substitute(dir,"/","\\",'g'))
        " return 1
    endif
    if islink == 1
        exe "!explorer '" . substitute(abs_dir,"/","\\\\",'g') . "'"
        return 1
    else
        return 0
    endif
endfunction

jfishe added a commit to jfishe/vimfiles that referenced this issue Mar 11, 2020
jfishe added a commit to jfishe/vimfiles that referenced this issue Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants