Closed Traap closed 10 months ago
dir_path = function()
return "images/" .. vim.fn.expand("%:t:r")
end
Any option can be dynamically configured using functions. See https://github.com/HakonHarnes/img-clip.nvim/blob/19d36300d23f9734e388298ff9b3f5ca74d28330/README.md?plain=1#L160-L166
Thank you for the tip. I will update my configuration and be sure to reference it in my video. Also, besides drag-n-drop, let me know if there is another feature you would like covered.
BTW: I must have missed the dynamic configuration in the README.md.
@Traap I've merged the drag and drop feature into main now. As discussed earlier the config will need to be altered slightly (See updated README).
Also, besides drag-n-drop, let me know if there is another feature you would like covered.
I think the drag and drop feature is the most interesting, but there's also the option to embed images directly as Base64. No other neovim plugins have these features, at least not that I am aware of. Note that if the Base64 size exceeds the max_base64_size
option (10 KB by default), it will save it as a file instead. Also note that drag and drop is designed to work in normal mode only (though can be enabled in insert mode using the drag_and_drop.insert_mode
opt).
The drag and drop feature does not work with all terminals, see https://github.com/HakonHarnes/img-clip.nvim?tab=readme-ov-file#drag-and-drop.
BTW: I must have missed the dynamic configuration in the README.md.
All good! It's quite a lengthy README.
Let me know if you have any more issues :)
@HakonHarnes I've attached a few screen captures. I'll note my observations after each image.
I've removed the comments so the image is smaller :) .1 dir_path is always "assets" regardless of what I specify.
I am using WSL2 + Arch + Windows Terminal. This is the same environment I used before updating.
@Traap config has changed slightly. See readme. You want to have the options under the "default" keyword now, i.e.:
opts = {
default = { -- add this
-- opts here ...
}
markdown = {
-- ...
}
}
This was done so the drag_and_drop
options are parsed correctly and not interpreted as a file type.
@HakonHarnes Got it. I'll update tomorrow and test when I get home from work. I knew it had to be simple.
@HakonHarnes - Quick update. I have a configuration that works using WSL2 + Ubuntu + Windows Terminal. I'll try a different computer tonight that hopefully will support the drag-and-drop feature.
Configurations I'll try drag-and-drop from are:
BTW: Thank you for your support.
Windows 11 + Windows Terminal + Power Shell
If drag and drop doesn't work with the web browser, try changing the shell to powershell
or pwsh
. See :h shell-powershell
. The reason is that command prompt won't allow you to run powershell -Command "curl ..."
to check if the URL is indeed an image. Either fix the permission issue or just switch to powershell
or pwsh
.
ArchLinux + [Alacritty| Kitty] + bspwm
Drag and drop should work with both files and URLs in Kitty, but not Alacritty. This is because Alacritty doesn't handle all drag and drop events. You can check the capabilities of the terminal by exiting Neovim and drag-and-dropping a file or URL into it. It should paste the path or URL to the image.
WSL2 + Ubuntu + Windows Terminal
Drag and drop won't work here, due to a neovim or WSL (not really sure) issue when system pasting. For some reason the system paste is fragmentet into multiple calls, even when just one line is pasted. Not really able to account for that in code unfortunately.
BTW: Thank you for your support.
No worries! Thanks for the interest in the plugin.
Also, besides drag-n-drop, let me know if there is another feature you would like covered.
@Traap Forgot to mention, the configurable templates with cursor positioning, figure labels etc. is also unique to this plugin, besides drag and drop and base64.
@HakonHarnes I've been using your plugin and preparing content for a video this weekend.
I have the following working from Arch + Alacritty or Kitty
I made switch neovim configurations YouTube video describing nvims. nvims install < 2 mins. You can install Traap to check my configuration on any desktop, editor, OS you have.
<leader>fy
will find all YouTube todo notes. I'll be high lighting, at minimum, the items I have marked with YouTube.
Any comments or recommendations is appreciatd.
I made switch neovim configurations YouTube video describing nvims. nvims install < 2 mins. You can install Traap to check my configuration on any desktop, editor, OS you have.
Cool stuff! Got it working straight away.
Any comments or recommendations is appreciatd.
I think it looks good, only thing is the 3rd and 4th YouTube comment is the same.
By the way, drag and drop on WSL is now working (#19).
I think it looks good, only thing is the 3rd and 4th YouTube comment is the same.
Thanks.
By the way, drag and drop on WSL is now working (#19).
Good catch.
I'll recording and editing this weekend. I'll let you know when I post.
My last item is to correctly demonstrate is embed_image_as_base64 = true
. Everything I have tried does not result in base64 string added to my test markdown file. The bash command below works correctly. I reviewed the plugin sources and your nvim configuration for clues too. It looks like it should work.
xclip -selection clipboard -o -t image/png | base64 | tr -d '\n'
Any ideas?
Images you are copying are probably below the max_base64_size
threshold. Either increase the max_base64_size
option or copy smaller images (e.g. simple icons). This was implemented so large images are not embedded as Base64.
@Traap did it resolve the issue?
@HakonHarnes I find out tonight on my Arch + Kitty & Alacritty machine.
I don't have base64 working with PasteImage or DnD on 1, 2, and 3 below. I was pleasantly surprised to lean how much DnD worked with these configurations too.
I start making my video tonight using Arch. I'll probably do RDC to a Windows11 machine to demonstrate some capabilities too.
I'm targeting a 20 to 30min video with decent coverage for several items.
base64 is the only item I can't get to work:
embed_image_as_base64 = true,
max_base64_size = 100,
If you can point me to a URL you texted base64 with, I'll gladly use it. Base64 is not a Use Case
that I imagine I woujld ever use, but it would be nice to demonstrate it for those that would chose to use it.
I added the following autocmd
vim.api.nvim_create_autocmd({ "BufEnter" }, {
group = augroup("wiki_lcd"),
command = "silent! lcd %:p:h",
pattern = { "*.md", "*.markdown", "*.wiki" },
})
To help with
dir_path = function()
return "images/" .. vim.fn.expand("%:t:r")
end,
file_name = "%Y-%m-%d-%H-%M-%S",
use_absolute_path = false,
relative_to_current_file = false,
The file path url was not correct when relative_to_current_file=true
. Consider:
The png files were saved to correct directory when the autocmd or relative_to_current_file=true
. The file path written to markdown page was wrong.
I use https://github.com/iamcco/markdown-preview.nvim to preview markdowns and https://github.com/lervag/wiki.vim to manage markdown, TeX, PlantUmlt, etc. wiki.vim provides WikiExport to create a pdf using pandoc for the current page.
Neither plugin could render foo/bar/baz/images/charlie/2024-01-04-22-17-13.png
when relative_to_current_file = true
.
note If I edited the file path to /foo/bar/....
both worked.
Setting relative_to_current_file = false
and adding the autocmd created the file path I had expected, which is actually relative the page; images/charlie/2024-01-04-22-17-13.png
Nested markdown pages with images in the same directory may not be a normal Use Case
for most people.
I tested nearly 100 combinations with all the machines I use over the past few weeks, over all I am pleased with the ease of use and performance of the plugin you have build. Nice work. Most likely I will switch to Kitty over Alacrity because I found, besides base64, everything just worked. Markdown preview was a nice bonus too.
base64 is the only item I can't get to work
Maybe it's the filetype? What's the output of :set filetype?
? I've extended filetype support in feat/extend-base64-ft-support. You can try it out by setting the branch
option using lazy.nvim.
Edit: I've merged the PR into main, no need to set the branch.
Here's an image less than 10 KB you can try: https://static.thenounproject.com/png/5024802-200.png
Base64 does not work with drag and drop yet, so you'll have to copy the image and invoke the PasteImage
command manually.
The file path written to markdown page was wrong.
Duplicate of #21. I will look into it this weekend.
Edit: Issue has been fixed and PR is merged into main.
I added the following autocmd
I've considered doing something similar in code (that is, temporarily changing the working directory), but I'm afraid it might have side effects, even if I restore the previous working directory. The solution is probably to implement something similar to python's relpath
.
Edit: Issue has been fixed and PR is merged into main.
I tested nearly 100 combinations with all the machines I use over the past few weeks, over all I am pleased with the ease of use and performance of the plugin you have build. Nice work.
Thank you!
Most likely I will switch to Kitty over Alacrity because I found, besides base64, everything just worked.
Good call. I also use Kitty.
@HakonHarnes commit a9b91b3 is promising. I'm building my Video script today. I'll update you again later today.
I'll update you again later today.
@Traap Did you get it working? If not, I'm happy to help you debug the issue.
@HakonHarnes Yes. I've been recording, re-recording, and editing videos today. I plan to post by Tuesday. BTW: I'm using tranlate.google.com to attempt to say you first name correctly. Norwegian sounds very different than English. I will attempt to use the Norwegian pronunciation.
BTW: I'm using tranlate.google.com to attempt to say you first name correctly. Norwegian sounds very different than English. I will attempt to use the Norwegian pronunciation.
Good luck! I'll be impressed if you get it right
@HakonHarnes "#34 IMG-CLIP.NVIM Paste or Drag-n-Drop Images to your Neovim Documents" has been uploaded to YouTube. Processing should be done in an hour or so. https://www.youtube.com/watch?v=4crDKASq9Nc
Thanks for your help.
@Traap
"#34 IMG-CLIP.NVIM Paste or Drag-n-Drop Images to your Neovim Documents" has been uploaded to YouTube. Processing should be done in an hour or so. https://www.youtube.com/watch?v=4crDKASq9Nc
I thoroughly enjoyed watching this! I also left a comment. If drag and drop on WSL still doesn't work feel free to open an issue :)
Thanks for your help.
Thank you for the interest in the plugin! Your thorough testing has definitely helped it become more robust.
The image below was done with clipboard-image.nivm. Notice the file name is appended to the images directory.
The image below was done with img -clip.nvim
I would like to achieve this functionality with img-clip.nvim.
I tried
This is achieved with clipboard-image.nvim with two separate configuration options. Here I how I have them define:
My img-clip.nvim configuration