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

Feature request. Links: inserting the link title from a linked file header #149

Closed
artkpv opened this issue Apr 30, 2021 · 6 comments
Closed

Comments

@artkpv
Copy link

artkpv commented Apr 30, 2021

Hello, thanks for this tool! I switched to this from VimWiki.

Could we have a header inserted into a link title? Probably a function that in normal or visual mode insert a title for a link under cursor from a linked file first header. That file is in markdown.

Example:

.
├── index.md
└── test.md

index.md:

Before:
[random url text](test)

After:
[First header in test.md](test)

test.md:

Preamble content

# First header in test.md

The content itself

vimrc:

filetype plugin on

let g:wiki_filetypes = ['wiki', 'md']
let g:wiki_link_target_type = 'md'

Environment:

❯ uname -a
Linux 5.11.15-arch1-2 #1 SMP PREEMPT Sat, 17 Apr 2021 00:22:30 +0000 x86_64 GNU/Linux
❯ nvim --version
NVIM v0.4.4
@lervag
Copy link
Owner

lervag commented Apr 30, 2021

This seems like a good idea that should not be too hard. I propose a function and a normal mode <plug> mapping that replaces the current link text with the first header in the target file, so that you could use it like this:

nmap <leader>wlh <plug>(wiki-link-fetch-header)

What do you think?

Note: this should work with both Markdown and wiki style links.

@artkpv
Copy link
Author

artkpv commented May 1, 2021

👍 Sounds good to me. Could we make it work in visual and do the same for a selected range? Thus to ease the task if many links.

@lervag
Copy link
Owner

lervag commented May 1, 2021

Could we make it work in visual and do the same for a selected range? Thus to ease the task if many links.

Yes, perhaps, but lets start with the simplest stuff first. Visual mode will require some more thought and discussion on how it should work, so I suggest you open a new issue on that when this issue is resolved (this helps keep things focused, which is good for me since I don't have that much time to work on stuff like this).

lervag added a commit that referenced this issue Jun 2, 2021
@lervag
Copy link
Owner

lervag commented Jun 2, 2021

I've pushed an update now - it's not finished, but it is something. The mapping is not created yet, but you can test by doing :call wiki#link#set_text_from_header() on top of a link. Let me know what you think.

@artkpv
Copy link
Author

artkpv commented Jun 3, 2021

Great! Tried on several links with absolute and relative path, then with a header down many lines below. Works smoothly.

Found issue with journal links like 2021-05-13-2218. It didn't fetch a header.

lervag added a commit that referenced this issue Jun 4, 2021
lervag added a commit that referenced this issue Jun 4, 2021
@lervag
Copy link
Owner

lervag commented Jun 4, 2021

I've pushed an update where <leader>wlh is not by default mapped to this action. I've tried to address the issue you got with the date. If it does not work still, then please provide a more detailed description.

@lervag lervag closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants