This repository contains a VIM paste pre-processing plugin suitable for editing text markup like Markdown or LaTeX.
The plugin provides p
and P
handlers for normal, insert and visual editing modes. Their
invocation triggers the following workflow:
- Plugin collects information about the paste action:
- Type of the current file
- Type of the content to be pasted. Currently the plugin distinguishes:
- HTTP(s) URLs.
- Image blobs (either
xclip
orwl-paste
is required for this).
- Possible text for annotations (e.g. gets the active visual selection)
- Substitution pattern is requested from the pre-configured dictionary. Example of the markdown
pattern for images:
![%T%C](%U)
where%T
stands for title,%U
- for the URL and%C
marks the cursor position after the paste is complete. - Finally, the plugin substitutes the information into the pattern and actually pastes the result into the buffer. For images the plugin saves blobs into a pre-configured directory and puts the path to the new file into the pattern.
Put the repository into the Vim runtime search path by using your favorite plugin manager.
-
Overwrite global options:
let g:pastething_insert_after_eol_move_right = 0 let g:pastething_insert_after_eol_command = 'p' let g:pastething_image_enabled = 1 let g:pastething_xclip_path = '/path/to/xclip' " `xclip` to extract images from clipboard let g:pastething_image_dir = 'img' " Save extracted images into the `./img` directory
Note:
g:pastething_insert_eol
is replaced with the top two variables listed above. -
Setup the substitution patterns for the file types of interest. Example:
./ftplugin/markdown.vim
:call g:pastething#pattern_set('markdown', g:pastething_type_url, "[%T%C](%U)") call g:pastething#pattern_set('markdown', g:pastething_type_img, "![%T%C](%U)")
./ftplugin/tex.vim
:call g:pastething#pattern_set('tex', g:pastething_type_url, "\\href{%U}{%T%C}")
-
Setup the paste command mappings:
nnoremap p :call pastething#paste_normal("p")<CR> nnoremap P :call pastething#paste_normal("P")<CR> vnoremap p :call pastething#paste_visual("p")<CR> inoremap <Esc>p <C-o>:call pastething#paste_insert("P")<CR>
- This plugin is inspired by img-paste
- clipboard-image.nvim