Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a custom yank function but am unable to figure out how to make it non-repeatable (like the normal yank). I have something similar to the following:

function! s:YankMotion(type)

    if a:type ==# 'line'
        normal! `[V`]y
    elseif a:type ==# 'char'
        normal! `[v`]y
        echom "Unexpected selection type"

nnoremap y :set opfunc=<sid>YankMotion<cr>g@

The problem is that if you do an operation that is repeatable (eg. cw) then yank something, then execute repeat again hitting ., you would expect to trigger cw but instead it tries to do the yank again.

Is it possible to fix this?

share|improve this question
What you do is no longer a regular yank: it's now a normal mode command and is thus repeatable with .. – romainl Sep 2 '13 at 19:57
Right, it makes sense as a default but in this case I don't want that behaviour. – eventualEntropy Sep 2 '13 at 22:48
up vote 2 down vote accepted

Vim will repeat the g@ command. Unfortunately, there's no way around this, and as you also cannot access the internal command history, it's impossible to restore the previously issued command. (You could hack something together for custom mappings that rely on repeat.vim, but it won't work for built-in commands.)

The only workaround I can think of is to change the mapping to use the normal y command, and trigger whatever is part of your "custom yank" afterwards, e.g. via :autocmd on CursorMoved,CursorHold.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.