Open FernandoBasso opened 2 years ago
OK, I tested this a good deal and found out a few things:
vim
without a (vim path/to/intro.{md,adoc,etc}
), the path is not updated later when actually opening a file.So, these are the challenges to overcome next.
If you use neovim with lua, you can achieve this functionality with the vanilla 'img-paste' like this:
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.wiki"},
callback = function(ev)
-- set the image directory to the same of the current filename
local current_file = vim.fn.expand('%:t:r')
vim.g.mdip_imgdir = current_file
vim.g.mdip_imgdir_intext = current_file
end
})
This only works when opening a *.wiki
file but it would be easy to adapt it.
NOTE: This is a work in progress.
Sometimes, we want to move a document around and then we have to search for its related images and move them around too, individually, or update image paths inside documents.
This PR allows for one extra setting which will make it possible to insert images in a directory named after the current buffer name.
For example, if the current buffer is
docs/intro.adoc
, the image will be copied todocs/intro.assets/<img-name>.png
.Or, if the current buffer is
notes/fp/concepts.md
, then the image will benotes/fp/concepts.assets/<img-name>.png
.It should work the same no matter the document file extension.
This allows for the document file and its assets directory to be moved together so that wherever the document is moved too, the images (or other assets, potentially) are moved together.
PS: I copied this idea from Typora (not sure if Typora invented it, but it is where I saw it and found it a useful approach for certain scenarios).