vimtricks.wiki Concise Vim tricks, one at a time.

How do I get a brief visual flash to confirm what text was just yanked in Neovim?

Answer

vim.highlight.on_yank()

Explanation

After yanking text in Vim it can be hard to tell exactly what was captured, especially with larger motions or text objects. Neovim's built-in vim.highlight.on_yank() function, triggered via the TextYankPost autocmd, briefly flashes a highlight over the yanked region so you can visually confirm the yank without examining registers.

How it works

Add this to your Neovim config (Lua):

vim.api.nvim_create_autocmd('TextYankPost', {
  callback = function()
    vim.highlight.on_yank()
  end,
})

Or with options to customise the highlight group and timeout:

vim.api.nvim_create_autocmd('TextYankPost', {
  callback = function()
    vim.highlight.on_yank({ higroup = 'IncSearch', timeout = 150 })
  end,
})

The TextYankPost event fires after every yank (and also after d, c, x — any operator that places text in a register), so the flash appears for all register writes, not just explicit y operations.

Example

With the snippet above in your config, pressing yip (yank inner paragraph) will flash the highlighted paragraph for 150ms and then return to normal display — giving you immediate visual feedback.

Tips

  • Available options for vim.highlight.on_yank(): higroup (highlight group name, default 'IncSearch'), timeout (milliseconds, default 150), and on_macro (whether to fire inside macros, default false).
  • To skip the flash when running macros (which is the default), leave on_macro as false. Set it to true if you want feedback during macro playback.
  • This is a Neovim-only feature. For Vim 8, similar behaviour requires a plugin.

Next

What is the difference between zt and z-Enter when scrolling the current line to the top of the screen?