lervag / wiki.vim

A wiki plugin for Vim
MIT License
656 stars 69 forks source link

Creating new links #233

Closed GregoryShields closed 2 years ago

GregoryShields commented 2 years ago

Coming from VimWiki, I am used to being able to append a forward slash to my link text and have VimWiki automatically create a new directory having the name that would've been given to the new file if the forward slash had not been appended, as well as have VimWiki automatically create a new "index" file inside the newly created directory. Because of my current configuration, the new file would be named "wiki.md".

In wiki.vim the new directory is created, but there is no automatically created index file containing the name specified in my configuration. Instead, I get a new file named ".md.md".

It appears that wiki.vim expects the new file name to be explicitly provided. However, I'm guessing that you'd agree that the behavior I'm describing makes sense. Although it is nice to be able to tell wiki.vim to place a new file inside a subdirectory that is not the current working directory, that's not something I would usually do.

Is this a feature that you would consider implementing? If you don't have time for it, I suppose I could start familiarizing myself with your code and take a run at it myself if you like this idea.

If there is any confusion as to what I am describing, I can put forth a hypothetical example.

Thanks in advance.

lervag commented 2 years ago

Do I understand correctly, that, given the minimal wiki:

root/
  -> index.md

Where index.md contains:

# Index

[[subdir/]]

If you follow the subdir link, then you expect to enter root/subdir/index.md and for the subdir directory to be created?

root/
  -> index.md
  -> subdir/
    -> index.md

And, further, that the issue is that index.md is not created and opened as expected?

lervag commented 2 years ago

Ah, no, I believe I reproduced it. I create a minimal test.vim file

set nocompatible
set runtimepath^=~/.local/plugged/wiki.vim
filetype plugin indent on
syntax enable

let g:wiki_root = '~/test_wiki'
let g:wiki_filetypes = ['md']
let g:wiki_link_extension = '.md'

" The following option is not neccessary to reproduce:
let g:wiki_link_target_type = 'md'

runtime plugin/wiki.vim
WikiIndex

With a single index.md inside ~/test_wiki. I then open with nvim --clean -u test.vim; for Vim, use vim -u test.vim. It will immediately open the root index.md file. I write subdir/, then from normal mode hit <cr> on top of subdir/ and we get the link [subdir/](subdir/.md).

Does this align with your experience/issue?

GregoryShields commented 2 years ago

Yes, that pretty much covers it.

Another nice thing that VimWiki does is that it replaces hyphens or underscores in the auto-generated link text with spaces to make it more readable, while preserving them in the auto-generated file or directory name.


As Sam Elliot said in The Big Lebowski, "I like your style, dude."

lervag commented 2 years ago

Another nice thing that VimWiki does is that it replaces hyphens or underscores in the auto-generated link text with spaces to make it more readable, while preserving them in the auto-generated file or directory name.

Could you give an example or two of this? I believe it is close to what is possible with :help g:wiki_map_link_create (but it sounds to be more or less the reverse).

lervag commented 2 years ago

I believe the original issue is solved; please test.

GregoryShields commented 2 years ago

Could you give an example or two of this? I believe it is close to what is possible with :help g:wiki_map_link_create (but it sounds to be more or less the reverse).

Well, let's say we wanted to create a wiki file pertaining to the movie Fight Club, but we want the directory created by wiki.vim to be named Fight-Club so as to avoid problems with directory names containing spaces. So we type in Fight-Club, press <CR> while on top of it, and wiki.vim produces a directory exactly as we typed it, but replaces the hyphen with a space for the descriptive link text.

So yeah, I suppose it's exactly the opposite of the example provided in :help g:wiki_map_link_create. If I'm not mistaken, I could take the example code and reverse the values for the second and third arguments to substitute() and I'd get what I'm after, except that instead of the RegEx I would just put in a literal space character. I'll give it a try.

lervag commented 2 years ago

Well, let's say we wanted to create a wiki file pertaining to the movie Fight Club, but we want the directory created by wiki.vim to be named Fight-Club so as to avoid problems with directory names containing spaces. So we type in Fight-Club, press <CR> while on top of it, and wiki.vim produces a directory exactly as we typed it, but replaces the hyphen with a space for the descriptive link text.

So, something like this:

don’t talk about Fight-Club/

  |
  | press <cr> with cursor somewhere on "Fight-Club/"
  |
  ∨

don’t talk about [Fight Club](Fight-Club/)

Or, from your text, it seems you don't want to type the / and still want it to create a directory link?

In any case, it is very useful with a very explicit example similar to what I'm trying to create. So, if I'm not interpreting your right, then please correct the example. It is also useful for adding tests when we add new functionality.

So yeah, I suppose it's exactly the opposite of the example provided in :help g:wiki_map_link_create. If I'm not mistaken, I could take the example code and reverse the values for the second and third arguments to substitute() and I'd get what I'm after, except that instead of the RegEx I would just put in a literal space character. I'll give it a try.

Feel free! However, would it not be better to turn this around? If you first write what you want to be the text of the link, then convert the text to a link with either i) select the words and press <cr> from visual mode, or ii) use the operator mapping on the desired text, by default gl. With a simple g:wiki_map_link_create, you can control the desired output format of the link.

lervag commented 2 years ago

As Sam Elliot said in The Big Lebowski, "I like your style, dude."

😃 ❤️

GregoryShields commented 2 years ago

So, something like this:

don’t talk about Fight-Club/

  | press <cr> with cursor somewhere on "Fight-Club/"

  |
  ∨

don’t talk about [Fight Club](Fight-Club/)

Yes, exactly like that. The reason I like this way of working, which is what I'm used to from VimWiki, is because I can create the link with my caret anywhere on the text of the target without having to do a selection. This is so because, I think, the link is created based off of either the selected text or the Vim "Word" (capital W) where the caret is located, meaning that hyphens will be included in the Word. Hence, there's no need for selecting anything before pressing <CR>. However, what I have now realized is that the function pointed to by g:wiki_map_link_create modifies the link text, not the link description. Whereas, what I'm needing is an option which will allow modifying the link description.

The other way to approach it, which would work just fine, would be to simply type words which will constitute the link with spaces between them, select them, and then press <CR>, allowing the custom function defined for g:wiki_map_link_create to replace the spaces with hyphens for the link text. I just happen to prefer it the other way round, as mentioned above.

Or, from your text, it seems you don't want to type the / and still want it to create a directory link?

No, that was just me being sloppy. Please forgive my error. In my mind I was thinking of an example where I'm just creating a simple link; not a new directory, but just a new file. However, I made the mistake of using the word "directory" when I was describing my example. Sorry about that.

I really appreciate your efforts in attempting to help me get wiki.vim working the way I want it to. Normally I try not to make the kinds of errors I made here. The only excuse I have is that my cognitive abilities are not quite up to par these days.

If you were to consider adding an option like I am suggesting, it would probably be good to also rename g:wiki_map_link_create to reflect the fact that what it is doing is modifying the link text. Of course, this project is your baby, so you can do whatever you like and I will respect it. I'm merely making a suggestion.

lervag commented 2 years ago

So, something like this:

don’t talk about Fight-Club/

  | press <cr> with cursor somewhere on "Fight-Club/"

  |
  ∨

don’t talk about [Fight Club](Fight-Club/)

Yes, exactly like that. The reason I like this way of working, which is what I'm used to from VimWiki, is because I can create the link with my caret anywhere on the text of the target without having to do a selection.

Ah, yes, that makes sense. Thanks!

Or, from your text, it seems you don't want to type the / and still want it to create a directory link?

No, that was just me being sloppy. Please forgive my error.

No problem; been there, done that. :)

I really appreciate your efforts in attempting to help me get wiki.vim working the way I want it to. Normally I try not to make the kinds of errors I made here. The only excuse I have is that my cognitive abilities are not quite up to par these days.

No worries!

If you were to consider adding an option like I am suggesting, it would probably be good to also rename g:wiki_map_link_create to reflect the fact that what it is doing is modifying the link text. Of course, this project is your baby, so you can do whatever you like and I will respect it. I'm merely making a suggestion.

I agree. I'll have to think about it, because I don't like to break backwards compatibility. But if it's necessary, then I won't mind doing it.


So, it seems I understand where you want to go with this. It remains to do an implementation. I obviously can't promise anything wrt. when I get around to it. I will look at it when I get the time. Feel free to dive into the code yourself if you have time; if you should propose a PR, then I will be glad to help get it merged.

GregoryShields commented 2 years ago

Thanks, Karl.

I think before I consider solving this myself and doing a PR, I'd like to solve the issue I have with iVim and wiki.vim. I will start a separate issue for that.

lervag commented 2 years ago

I believe this is now resolved. Essentially, I changed the existing g:wiki_map_create_link and called the new option g:wiki_map_text_to_link. I believe the updated documentation should adequately explain how to use this, and I believe you can use it to achieve your desired goal. Let me know what you think!

GregoryShields commented 3 months ago

Wow, I can't believe it has been two years. I'm so sorry I dropped the ball, because you have always been so enthusiastic and receptive to my questions.

I'm looking at this now and I see that the new option g:wiki_map_text_to_link that you created back then no longer exists.

When I look at the current code, I see that the file... wiki.vim/autoload/wiki/link/word.vim ...no longer exists. I do see this file... wiki.vim/autoload/wiki/link/class.vim ...in the master branch. I know that I should RTFM, but if you have any comment on the evolution that happened relative to this, I'd be very interested.

lervag commented 3 months ago

Wow, I can't believe it has been two years.

I know, time flies!

I'm so sorry I dropped the ball, because you have always been so enthusiastic and receptive to my questions.

No problem; life happens to all of us. ;)

I'm looking at this now and I see that the new option g:wiki_map_text_to_link that you created back then no longer exists.

When I look at the current code, I see that the file... wiki.vim/autoload/wiki/link/word.vim ...no longer exists. I do see this file... wiki.vim/autoload/wiki/link/class.vim ...in the master branch. I know that I should RTFM, but if you have any comment on the evolution that happened relative to this, I'd be very interested.

Well, I believe I found a more robust way to solve these things. The new option you should learn is g:wiki_link_creation - it was introduced in commit 62d63bcaad768717d9b6447e057e4d7a927ced99. For more info, see #296.

You may also want to read up on g:wiki_link_schemes, which is also relatively new (or newer than 2 years).

GregoryShields commented 2 months ago

Thanks for the heads up, and for taking the time to respond. I'll check those out.