citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

repeat.vim (2553B)


      1 " repeat.vim - Let the repeat command repeat plugin maps
      2 " Maintainer:   Tim Pope
      3 " Version:      1.0
      4 
      5 " Installation:
      6 " Place in either ~/.vim/plugin/repeat.vim (to load at start up) or
      7 " ~/.vim/autoload/repeat.vim (to load automatically as needed).
      8 "
      9 " Developers:
     10 " Basic usage is as follows:
     11 "
     12 "   silent! call repeat#set("\<Plug>MappingToRepeatCommand",3)
     13 "
     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.
     18 "
     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.
     24 "
     25 " Make sure to call the repeat#set function _after_ making changes to the
     26 " file.
     27 
     28 if exists("g:loaded_repeat") || &cp || v:version < 700
     29     finish
     30 endif
     31 let g:loaded_repeat = 1
     32 
     33 let g:repeat_tick = -1
     34 
     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
     40 endfunction
     41 
     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)
     48     else
     49         call feedkeys((a:count ? a:count : '') . '.', 'n')
     50     endif
     51 endfunction
     52 
     53 function! s:wrap(command,count)
     54     let preserve = (g:repeat_tick == b:changedtick)
     55     exe 'norm! '.(a:count ? a:count : '').a:command
     56     if preserve
     57         let g:repeat_tick = b:changedtick
     58     endif
     59 endfunction
     60 
     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>
     65 
     66 augroup repeatPlugin
     67     autocmd!
     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
     70 augroup END
     71 
     72 " vim:set ft=vim et sw=4 sts=4: