tpope / vim-repeat

repeat.vim: enable repeating supported plugin maps with "."
http://www.vim.org/scripts/script.php?script_id=2136
2.61k stars 83 forks source link

How to use vim-repeat #51

Closed fdietze closed 9 years ago

fdietze commented 9 years ago

Hi, I don't understand from the docs how to use vim-repeat with my own function. What I came up with is not working:

function! ToggleEndChar(charToMatch)
    let save_cursor = getpos(".") " backup cursor
    s/\v(.)$/\=submatch(1)==a:charToMatch ? '' : submatch(1).a:charToMatch
    call setpos('.', save_cursor) " restore cursor
endfunction

nnoremap <silent> <Leader>, :call ToggleEndChar(',')<CR>\
    silent! call repeat#set("ToggleEndChar(',')<CR>", -1)

What am I doing wrong?

tpope commented 9 years ago

You need to call repeat#set in the function, and you need to give it a valid Vim map (not just a function invocation).