1 " repeat.vim - Let the repeat command repeat plugin maps
6 " Place in either ~/.vim/plugin/repeat.vim (to load at start up) or
7 " ~/.vim/autoload/repeat.vim (to load automatically as needed).
10 " Basic usage is as follows:
12 " silent! call repeat#set("\<Plug>MappingToRepeatCommand",3)
14 " The first argument is the mapping that will be invoked when the |.| key is
15 " pressed. Typically, it will be the same as the mapping the user invoked.
16 " This sequence will be stuffed into the input queue literally. Thus you must
17 " encode special keys by prefixing them with a backslash inside double quotes.
19 " The second argument is the default count. This is the number that will be
20 " prefixed to the mapping if no explicit numeric argument was given. The
21 " value of the v:count variable is usually correct and it will be used if the
22 " second parameter is omitted. If your mapping doesn't accept a numeric
23 " argument and you never want to receive one, pass a value of -1.
25 " Make sure to call the repeat#set function _after_ making changes to the
28 if exists("g:loaded_repeat") || &cp || v:version < 700
31 let g:loaded_repeat = 1
33 let g:repeat_tick = -1
35 function! repeat#set(sequence,...)
36 silent exe "norm! \"=''\<CR>p"
37 let g:repeat_sequence = a:sequence
38 let g:repeat_count = a:0 ? a:1 : v:count
39 let g:repeat_tick = b:changedtick
42 function! s:repeat(count)
43 if g:repeat_tick == b:changedtick
44 let c = g:repeat_count
45 let s = g:repeat_sequence
46 let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
47 call feedkeys(cnt . s)
49 call feedkeys((a:count ? a:count : '') . '.', 'n')
53 function! s:wrap(command,count)
54 let preserve = (g:repeat_tick == b:changedtick)
55 exe 'norm! '.(a:count ? a:count : '').a:command
57 let g:repeat_tick = b:changedtick
61 nnoremap <silent> . :<C-U>call <SID>repeat(v:count)<CR>
62 nnoremap <silent> u :<C-U>call <SID>wrap('u',v:count)<CR>
63 nnoremap <silent> U :<C-U>call <SID>wrap('U',v:count)<CR>
64 nnoremap <silent> <C-R> :<C-U>call <SID>wrap("\<Lt>C-R>",v:count)<CR>
68 autocmd BufLeave,BufWritePre,BufReadPre * let g:repeat_tick = (g:repeat_tick == b:changedtick || g:repeat_tick == 0) ? 0 : -1
69 autocmd BufEnter,BufWritePost * if g:repeat_tick == 0|let g:repeat_tick = b:changedtick|endif
72 " vim:set ft=vim et sw=4 sts=4: