img-paste-devs / img-paste.vim

paste image to markdown
383 stars 86 forks source link

Implement imgdir_filename_prefix #61

Open jdorel opened 3 years ago

jdorel commented 3 years ago

Use final_imgdir and final_imgdir_intext to support multiple files Rework SafeMakeDir to not call any global variables

Fix #50 not working when editing multiple files

Wadekiny commented 2 years ago

When opening vim, the .vimrc file will be run once, and g:mdip_imgdir will only be set once. But opening a new buffer in vim doesn't reset g:mdip_imgdir, so g:mdip_imgdir remains unchanged, causing this problem. My solution is this:

add codes in .vimrc

function! MdPasteImage() 
    let g:mdip_imgdir_intext = './md_images_' . expand('%:r')
    let g:mdip_imgdir = './md_images_' . expand('%:r')
    "echo g:mdip_imgdir
    "echo g:mdip_imgdir_intext
    call mdip#MarkdownClipboardImage()

endfunction

autocmd FileType markdown nmap <buffer><silent> <leader>p :call MdPasteImage()<CR>