1
votes

When I am yanking into registers, I often mistype the "x syntax, so I would like to have a confirmation of which register it used to yank the text.

For instance, my ideal output if I were to type "x3yy would be "3 lines yanked into x" instead of the current "3 lines yanked". Is it possible to modify this report somehow? Ideally it would also work for deleting, etc.

2

2 Answers

3
votes

This has been addressed in recent Vim builds, starting with version 8.0.0724: the message for yanking doesn't indicate the register.

Once you've upgraded (either by waiting until a package for your operating system is available, or compiling Vim yourself), the message on for example "a4yy will be:

4 lines yanked into "a
2
votes

This feature was added to the after patch 8.0.0724 (kudos for Ingo Karkat for reporting it).

Neovim, as of now, hasn't merged this patch. However, it implements TextYankPost, which allows you to hack a similar behavior, as it provides the type of operation, the register used and the contents that was copied to the register.

Taking that into consideration, the following code snippet would do what you are asking for:

function! s:better_operator_message()
  let number = len(v:event['regcontents'])

  if v:event['operator'] == 'c' || v:event['operator'] == 'd'
    let message = number . ' fewer lines'
  elseif v:event['operator'] == 'y'
    let message = number . ' lines yanked'
  else
    return
  endif

  if v:event['regname'] != ''
    let message = message . ' into register ' . v:event['regname']
  endif

  echom message
endfunction

set report=10000000000
augroup better_operator_message
  autocmd!
  autocmd TextYankPost * call <sid>better_operator_message()
augroup end

I've made this snippet available as a plugin, in case you're interested.