Leeren
Leeren

Reputation: 2081

How to have vim always call a function after any yank

Is there a way to have vim always call a defined function after any yanking operation? Doing something like nnoremap y y:function<CR> results in abnormal behavior.

Upvotes: 1

Views: 1091

Answers (1)

Peter Rincker
Peter Rincker

Reputation: 45117

The TextYankPost event will be triggered after text has been yanked or deleted. See :h TextYankPost for more help.

augroup Example
    autocmd!
    autocmd TextYankPost * if v:event.operator ==# 'y' | call somefunction() | endif
augroup END

I know that vim-highlightedyank uses the TextYankPost event and maybe a place to look for inspiration.

Upvotes: 5

Related Questions