Vim and Neovim plugin to highlight pasted text in a terminal.
When you paste something (like Control Shift V in many terminal emulators), this plugin detects and highlights the new text.
It is similar to vim-highlightedyank, but for pasted text.
The plugin is tested in Vim 8.1 and Neovim 0.5.
You can use Vim packages to install it:
-
For Vim:
$ YOUR_PACK_NAME=AnyNameYouWant $ cd ~/.vim/pack/$YOUR_PACK_NAME/start $ git clone https://github.com/ayosec/hltermpaste.vim.git hltermpaste
-
For Neovim:
$ YOUR_PACK_NAME=AnyNameYouWant $ cd ~/.local/share/nvim/site/pack/$YOUR_PACK_NAME/start $ git clone https://github.com/ayosec/hltermpaste.vim.git hltermpaste
If you prefer any other plugin manager, it should work with most of them. Please open an issue if you find any problem with your preferred plugin manager.
Vim has support for bracketed paste. If it is enabled, Vim sets the paste
option when the paste starts, and unset it when the paste is finished. This
plugin detects those actions with the OptionSet event, and tracks the
cursor position before and after the events. Then, it highlights the region
between both positions.
In Neovim we only need to use a custom paste handler with vim.paste. The
handler tracks the cursor position before and after the paste, and then
highlights the region between both positions.
To control the duration of the highlight set the value of
g:hltermpaste_timeout to a number of milliseconds. By default, it is 500.
For example, to set the duration to 1 second:
" Highlight for 1 second
let g:hltermpaste_timeout = 1000By default, the pasted text is highlighted as IncSearch. You can use a
different highlighting group with g:hltermpaste_match_group. For example:
let g:hltermpaste_match_group = "DiffAdd"Also, you can define your own colors with a new highlighting group. For example:
let g:hltermpaste_match_group = "PastedText"
hi def PastedText term=reverse ctermbg=4 guibg=BluePlease see the documentation for :highlight to see all available options.
To disable the plugin, set g:loaded_hltermpaste to any value:
let g:loaded_hltermpaste = 1The command :HighlightTermPasteVisual creates a visual selection with the
latest pasted text.