img-paste-devs / img-paste.vim Goto Github PK
View Code? Open in Web Editor NEWpaste image to markdown
paste image to markdown
Rather than going via a temporary file, would it be possible to support base64-inline-encoding?
echo "\![Pasted image](data:type=image/png,$(xclip -selection clipboard -o -t image/png | base64 | tr -d '\n'))"
Hi,
Thanks for a great plugin! Exactly what I was looking for when taking notes and writing summaries in my personal wiki.
Would it be possible to extend this to other markup languages as well? I can definitely see the use of having similar behaviour in e.g. LaTeX. I'm no vimscript expert, but one solution could be to change the hard-coded inserts in
https://github.com/ferrine/md-img-paste.vim/blob/94c23fc5ce9929fc0b5cfb0b4b80b5afe6ac4ebe/plugin/mdip.vim#L179 and https://github.com/ferrine/md-img-paste.vim/blob/94c23fc5ce9929fc0b5cfb0b4b80b5afe6ac4ebe/plugin/mdip.vim#L181 to insert the variables g:mdip_paste_before
and g:mdip_paste_after
instead of ![Image](
and )
, respectively. Then one could define the g:mdip_paste_
variables based on filetype:
autocmd FileType latex let g:mdip_paste_before = '\includegraphics{'
autocmd FileType latex let g:mdip_paste_after = '}\n\caption{Image}'
autocmd FileType markdown let g:mdip_paste_before = '![Image]('
autocmd FileType markdown let g:mdip_paste_after = ')'
This would also make it possible to define the variables as empty, such that only the image path is pasted.
There are probably better ways to do this, to make it more aligned with ftplugin and snippets, but that is beyond my knowledge.
The table in section "Extend to other markup languages" has three typos related to the default function names. For instance, the function name "MarkdownPasteImate" should be "MarkdownPasteImage". Same applies to the other two column. Thanks.
Plugin installs, mapping is active, but plugin fails silently either with mapping or by calling
:call mdip#MarkdownClipboardImage()
directly. Any ideas?
PS - The 'img' directory is created... but is also empty...
Walyand is the new display server for Linux. It does not use xsel. The clipboard tool for Wayland is wl-clipboard:
https://github.com/bugaevc/wl-clipboard
As a starter, NeoVim identifies which clipboard to use using this code in /usr/share/nvim/runtime/autoload/provider/clipboard.vim
elseif exists('$WAYLAND_DISPLAY') && executable('wl-copy') && executable('wl-paste')
For example, I am editing a file names "test.md". I want to save the image in the "./test/" folder when I paste.
Is it change the let g:mdip_imdir = 'image' in vimrc file? I don't know how to fill in. How to get the filename...
Please tell me , I am sincerely want to know, thank you very much!
Hello, ferrine.
I'm using this plugin and it really suits my work except for one thing that I can only name a specific image file with a random name or a fixed name but not a meaningful name.
So could you please improve it? My suggestion is as followed:
diff --git a/plugin/mdip.vim b/plugin/mdip.vim
index ee3eff4..ea71c4f 100644
--- a/plugin/mdip.vim
+++ b/plugin/mdip.vim
@@ -74,7 +74,7 @@ endfunction
function! mdip#MarkdownClipboardImage()
let workdir = SafeMakeDir()
" change temp-file-name and image-name
- let g:mdip_tmpname = RandomName()
+ let g:mdip_tmpname = input("File Name? ", RandomName())
Thanks again for your cool plugin.
My first thought is to use <img src="drawing.jpg" alt="drawing" width="200"/>
, where should I change the code?
I was not able to copy/paste. After some research I realized I can't copy/paste text from system register (i.e *) in vim.
Some terminals do not have clipboard support. To check if the terminal has clipboard support not not run vim --version | grep clipboard
, if it shows -clipboard, then it needs to be fixed by installing vim-gtk
on ubuntu. Now you can copy text to system clipboard using "+y
then paste on other softwares using Ctrl-v, as usual, and copy on sytem using Ctrl-c and paste in vim using "+p
Hence, I feel this should be mentioned in readme to avoid frustration of the users. I can raise a PR to add the same.
I am on windows7 gvim, I copy a image, after i enter the keybind, the directory will be created, but there is no image file.
But when I screenshot a image ,the directory and picture will be created。so i don't know what happend,why ?
I was having similar issues as #58, and I think I've found out why.
This only works for the C:
drive. Replacing it with the code below worked for other drives:
let tmpfile = substitute(tmpfile, "\\\\\\\\mnt\\\\\\\\\\(.\\)", "\\1:", "g")
" I found this to be more readable:
let tmpfile = substitute(tmpfile, '\\\\mnt\\\\\(.\)', '\1:', "g")
PS: I have xclip
properly set up in Ubuntu 20.04 1 , so the Linux saving functions are working properly.
Using x410. ↩
Hi, the plugin doesn't seem to work when the folder of your file has spaces in it. I tried different directories with and without spaces and this seems to be the case. It simply hangs after asking for file name
I tried scanning the code but couldn't find the error
Thanks!
I'm running on a macOS Catalina. This is my entire vimrc configuration.
When I ran this plug-in, I came across the error below. And I find the function "SaveFileTMP()", specifically, the function "IsWSL()", has some trouble. Because when I try to run the function "has("unix")", it keeps telling me "TRUE". However, I don't have such a file named "/proc/version".
By the way, my OS version is macOS 10.15.6 and my vim version is 8.2.1400.
My Error (some of them are Chinese, you can translate them)
My Experiment
I made a change to be able to input the name of the image instead of using the current date, as it is now.
Would you be interested in including this to the plugin?
I'm a bit busy with other stuff and it is hard to keep track of fixes submitted to this repository, maybe someone can help with that?
It worked before but for some reason it behaves abnormally even after I reinstall it.
After I hit key p, it inserted the text below in my buffer instead of calling pasting function.
autocmd FileType markdown nmap <silent> <leader>p :call mdip#MarkdownClipboardImage()<CR>
Hi, I found that this plugin works great on my laptop locally. But if I login a remote server over ssh, it just create a empty 'img' folder and insert no line to the md file. Also there are no picture file inside the 'img' folder. I guess it should relate to the xclip. Did you encounter the same problem? Is there any solution when working on a remote server?
my only configuration is shortcut as follow :
autocmd FileType markdown nmap p :call mdip#MarkdownClipboardImage()
but pasting not work for me, while development console print img "not found", and i'm using vim-instant-markdown to preview in explorer.
pls help me
thanks very much
Hi.
I'm running ubunu and WSL v2. When pasting an image from the clipboard I was getting an error thrown by the wslpath command. When this command is executed to resolve a path of a nonexistent file you get a "No such file or directory" error. This happens when trying to resolve the path AND the new image name.
I was able to work around this by resolving the folder path first and then appending the new image name
33 function! s:SaveFileTMPWSL(imgdir, tmpname) abort
34 let folder_path = substitute(system("wslpath -m ".a:imgdir), '\n\+$', '', '')
35 let tmpfile = folder_path . '/' . a:tmpname . '.png'
36
37
38 let clip_command = "Add-Type -AssemblyName System.Windows.Forms;"
39 let clip_command .= "if ([Windows.Forms.Clipboard]::ContainsImage()) {"
40 let clip_command .= "[Windows.Forms.Clipboard]::GetImage().Save(\\\""
41 let clip_command .= tmpfile ."\\\", [System.Drawing.Imaging.ImageFormat]::Png) }"
42 let clip_command = "powershell.exe -sta \"".clip_command. "\""
43
44 call system(clip_command)
45 if v:shell_error == 1
46 echo "error"
47 return 1
48 else
49 return tmpfile
50 endif
51 endfunction
When I paste the image the name defaults to Image
unless I edit it.
Can it just be whatever I name the file as?
I'm using a .vimrc
configuration that is verified working in vim within iTerm2 (terminal emulator). The plugin works really well in the terminal instance of vim.
In MacVim, the plugin does not work properly. It inserts an image link in the markdown file, but doesn't increment the image name.
![](img/image0.png)
- it is not incremented from 0
.img
folder, but each one is named tmp.png
(never renamed image0
, image1
, etc.) so each successive image overwrites the file.May be interesting to test with gVim on Linux.
I am on Ubuntu 18.04 of WSL 1, and xclip version is 0.12(I also downloaded the 0.13 version, and it niether does not work)
After i enter the keybind, the directory will be created, but there is no image file.
I think the problem may be the xclip. So i try the command:
$ xclip -selection clipboard -t image/png -o > 1.png
Error: target image/png not available
Then i check the targets xclip supports.
$ xclip -selection clipboard -t TARGETS -o
TARGETS
COMPOUND_TEXT
UTF8_STRING
STRING
There is no image/png.
So is there another way i can use this wonderful plugin?
Hi there, awesome idea for a plugin! I haven't been able to get it working, yet. I get this error when I'm in a markdown file, have an image on my clipboard, and use <leader>p
to paste:
E117: Unknown function: mdip#MarkdownClipboardImage
Here's my system info:
OS: 64bit Mac OS X 10.13.2 17C205
Kernel: x86_64 Darwin 17.3.0
Uptime: 1d 20h 43m
Packages: 257
Shell: zsh 5.4.2
Resolution: 2880x1800
CPU: Intel Core i7-4770HQ @ 2.20GHz
RAM: 16384MiB
Vim version:
❯❯❯ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jul 26 2017 19:10:24)
Included patches: 1-503, 505-642
Compiled by [email protected]
Normal version without GUI. Features included (+) or not (-):
+acl +file_in_path -mouse_sgr +tag_old_static
-arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float -mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm -termguicolors
-browse -footer +multi_byte +terminfo
+builtin_terms +fork() +multi_lang +termresponse
+byte_offset -gettext -mzscheme +textobjects
+channel -hangul_input +netbeans_intg +timers
+cindent +iconv +num64 +title
-clientserver +insert_expand +packages -toolbar
-clipboard +job +path_extra +user_commands
+cmdline_compl +jumplist -perl +vertsplit
+cmdline_hist -keymap +persistent_undo +virtualedit
+cmdline_info +lambda +postscript +visual
+comments -langmap +printer +visualextra
-conceal +libcall -profile +viminfo
+cryptv +linebreak +python/dyn +vreplace
+cscope +lispindent -python3 +wildignore
+cursorbind +listcmds +quickfix +wildmenu
+cursorshape +localmap +reltime +windows
+dialog_con -lua -rightleft +writebackup
+diff +menu +ruby/dyn -X11
+digraphs +mksession +scrollbind -xfontset
-dnd +modify_fname +signs -xim
-ebcdic +mouse +smartindent -xpm
-emacs_tags -mouseshape +startuptime -xsmp
+eval -mouse_dec +statusline -xterm_clipboard
+ex_extra -mouse_gpm -sun_workshop -xterm_save
+extra_search -mouse_jsbterm +syntax
-farsi -mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -o vim -lm -lncurses -liconv -framework Cocoa
Here's my .vimrc
:
❯❯❯ cat ~/.vimrc
" -------------------------------------------- options ---------------------------------------------
set number " Show line numbers
set linebreak " Break lines at word (requires Wrap lines)
set showbreak=+++ " Wrap-broken line prefix
set textwidth=82 " Line wrap (number of cols)
set showmatch " Highlight matching brace
set visualbell " Use visual bell (no beeping)
set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set ignorecase " Always case-insensitive
set incsearch " Searches for strings incrementally
set autoindent " Auto-indent new lines
set shiftwidth=4 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set softtabstop=4 " Number of spaces per Tab
" ----------------------------------- variables ----------------------------------
let mapleader = "," " Remap <leader> key to comma
" ----------------------------------- vim-plug -----------------------------------
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
Plug 'ferrine/md-img-paste.vim'
" Initialize plugin system
call plug#end()
" -------------------------- ferrine's md-img-paste.vim --------------------------
autocmd FileType markdown nmap <silent> <leader>p :call mdip#MarkdownClipboardImage()<CR>
" there are some defaults for image directory and image name, you can change them
" let g:mdip_imgdir = 'img'
" let g:mdip_imgname = 'image'
Thanks for any help you might be able to give! I'm hoping to contribute to this project, as I'll be using it all the time (if I can get it working).
I use the static site generator Hugo. The inside of a Hugo site looks like this:
content
├── L1
│ ├── L1.md
│ └── L2
│ ├── L2.md
│ └── L3
│ └── L3.md
└── L1_2
├── L1_2.md
└── L1_3.md
static
└── img
└── imagepaste.png
All images are saved in /static/img
and referenced in markdown as ![](/static/img/imagepaste.png)
Is it possible to make this plugin work such that in any "level" of markdown file in the content directory, the image is pasted in the /static/img directory?
Hello,
the plugin works great when I open a simple file with vim: vim myfile.md
.
However, once in vim I commonly use the explorer to browse to other files, with :Explorer
or :o
.
On the new file opened, it doesn't work.
I use <leader>p
key binding (explaining the strange paste behavior), it seems that in the other files the plugin doesn't work.
I am new to GitHub and could not find your mail to contact you.
I adapted the plugin to work with windows and powershell.
I would like to share it with you if you are interested.
The issue of #33 and #35 resulted in an error occurring, and then the s:SaveFileTMPLinux
function running after the error. That issue affects macOS and WSL systems.
#36 fixed the problem for macOS and Windows. Now instead of throwing and error and running s:SaveFileTMPLinux
, s:SaveFileTMPWSL
is called and breaks the terminal.
My advice would be to remove the WSL function and let the s:SaveFileTMPLinux
function run when WSL is detected.
My platform is windows 10. Is it ok for it?
I am on Ubuntu 18.04 of WSL 1, and xclip version is 0.12(I also downloaded the 0.13 version, and it niether does not work)
After i enter the keybind, the directory will be created, but there is no image file.
I think the problem may be the xclip. So i try the command:
$ xclip -selection clipboard -t image/png -o > 1.png
Error: target image/png not available
Then i check the targets xclip supports.
$ xclip -selection clipboard -t TARGETS -o
TARGETS
COMPOUND_TEXT
UTF8_STRING
STRING
There is no image/png.
So is there another way i can use this wonderful plugin?
An option to put all the images of current markdown file in a directory with current filename without the .md
extension and _img
suffix would be nice addition. I use this plugin heavily for my blog posts, it'd help me a lot.
I hope I can make the mdip_imgdir
variable to take formats which allow embedding filenames in it. Something like let g:mdip_imgdir = '${FILE}_img
The PR #23 brought selection typing for image name, it should ideally fill same image names in alt text and image path.
These are very minor improvements, I'd like to work on them once I get some time.
I use deepin screenshot, but I get a picture of the xpm suffix
![Image](pic/pulic_var.xpm)
This plugin was working great until I updated my Vim install (new install is with brew, version deets below, I don't remember what version/install method the old install was). Now when I invoke the plugin with <leader>p, it asks for a filename, but once I enter one and hit Enter, nothing (visible) happens. The directory for the image is created, but no image is saved into that directory, and nothing shows up in the file I'm editing. I confirm I have image data in the clipboard because I can copy it into other applications.
It's possible some other stuff changed on my system between the last time I used this plugin and today also, perhaps a Mac update.
Let me know how I can debug this further, thanks!
Here's the relevant part of the vimrc (not including the Vundle stuff):
autocmd FileType markdown nmap <buffer><silent> <leader>p :call mdip#MarkdownClipboardImage()<CR>
And my vim version:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 8 2021 03:27:03)
macOS version - x86_64
Included patches: 1-2575
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +cmdline_hist +ex_extra +jumplist +mouse_dec +perl -sound +textprop +writebackup
+arabic +cmdline_info +extra_search +keymap -mouse_gpm +persistent_undo +spell +timers -X11
+autocmd +comments -farsi +lambda -mouse_jsbterm +popupwin +startuptime +title -xfontset
+autochdir +conceal +file_in_path +langmap +mouse_netterm +postscript +statusline -toolbar -xim
-autoservername +cryptv +find_in_path +libcall +mouse_sgr +printer -sun_workshop +user_commands -xpm
-balloon_eval +cscope +float +linebreak -mouse_sysmouse +profile +syntax +vartabs -xsmp
+balloon_eval_term +cursorbind +folding +lispindent +mouse_urxvt -python +tag_binary +vertsplit -xterm_clipboard
-browse +cursorshape -footer +listcmds +mouse_xterm +python3 -tag_old_static +virtualedit -xterm_save
++builtin_terms +dialog_con +fork() +localmap +multi_byte +quickfix -tag_any_white +visual
+byte_offset +diff +gettext +lua +multi_lang +reltime -tcl +visualextra
+channel +digraphs -hangul_input +menu -mzscheme +rightleft +termguicolors +viminfo
+cindent -dnd +iconv +mksession +netbeans_intg +ruby +terminal +vreplace
-clientserver -ebcdic +insert_expand +modify_fname +num64 +scrollbind +terminfo +wildignore
+clipboard +emacs_tags +ipv6 +mouse +packages +signs +termresponse +wildmenu
+cmdline_compl +eval +job -mouseshape +path_extra +smartindent +textobjects +windows
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -
lm -lncurses -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.4 -mmacosx-version-min=11.2 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.32.
1_1/lib/perl5/5.32.1/darwin-thread-multi-2level/CORE -lperl -L/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -lpython3.9 -fram
ework CoreFoundation -lruby.3.0 -L/usr/local/Cellar/ruby/3.0.0_1/lib
I add these in vimrc
let g:mdip_imgname = 'test'
function SavePic()
let pp = expand('%:t:r')
let g:mdip_imgdir = pp
endfunction
autocmd BufEnter *.md call SavePic()
and it worked in windows.
Now I use it in Ubuntu 20.4, it can save the picture in the custom path, but in the markdown file, it inputs a default name and default path text.
After "leader"p, If I just press "Enter", it shows:
![Image](img/test_2020-07-26-22-22-42.png)
If I type "asdf", it shows:
![Image](img/asdf.png)
Which means, these setting in Windows, it worked. But in Ubuntu, it didn't.
And in Ubuntu, it's saving function is OK. But the input text, it didn't work.
I think may be the problem is in the mdip.vim, the Linux part?
I'm try my hard to read the mdip.vim file, but it's difficult to me...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.