mirror of
https://github.com/tpope/vim-repeat.git
synced 2026-09-10 07:16:26 -04:00
Compare commits
54 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65846025c1 | ||
|
|
5bd4c87a14 | ||
|
|
a89a4d0760 | ||
|
|
4bac219cc0 | ||
|
|
8b4435c5bb | ||
|
|
e0466d2b24 | ||
|
|
24afe922e6 | ||
|
|
c947ad2b6a | ||
|
|
ae361bea99 | ||
|
|
0b9b5e742f | ||
|
|
5974ea07ac | ||
|
|
eb97e729be | ||
|
|
43d2678fa5 | ||
|
|
1ea8a5325b | ||
|
|
8fe8bde4f4 | ||
|
|
8106e142df | ||
|
|
1b82cad74c | ||
|
|
070ee90324 | ||
|
|
7a6675f092 | ||
|
|
5bacc6f805 | ||
|
|
e42a430e64 | ||
|
|
655dd3e2be | ||
|
|
c4f9f159e6 | ||
|
|
7568a9604b | ||
|
|
b01aafbd8d | ||
|
|
751b369cc3 | ||
|
|
d9fbf5a137 | ||
|
|
88e7d7e5c3 | ||
|
|
4895d90a14 | ||
|
|
cffb2e7578 | ||
|
|
b06684a195 | ||
|
|
ad89be240f | ||
|
|
bd3b517235 | ||
|
|
006694e0f5 | ||
|
|
7f09c18d2e | ||
|
|
193f4866df | ||
|
|
b6bdd0f2d0 | ||
|
|
80261bc531 | ||
|
|
5eba0f19c8 | ||
|
|
2a3c5f8e3c | ||
|
|
a81bef7603 | ||
|
|
8ee7450812 | ||
|
|
aeb3d6cd89 | ||
|
|
d8f7fe7598 | ||
|
|
f1d0fbbdf4 | ||
|
|
613eb1c812 | ||
|
|
d75a544b78 | ||
|
|
2914f11f74 | ||
|
|
476c28084e | ||
|
|
1118a8324f | ||
|
|
cdffdd4381 | ||
|
|
ecab7ca1b7 | ||
|
|
bef6db85d9 | ||
|
|
1f19cf2a03 |
48
README.markdown
Normal file
48
README.markdown
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# repeat.vim
|
||||
|
||||
If you've ever tried using the `.` command after a plugin map, you were
|
||||
likely disappointed to discover it only repeated the last native command
|
||||
inside that map, rather than the map as a whole. That disappointment
|
||||
ends today. Repeat.vim remaps `.` in a way that plugins can tap into
|
||||
it.
|
||||
|
||||
The following plugins support repeat.vim:
|
||||
|
||||
* [surround.vim](https://github.com/tpope/vim-surround)
|
||||
* [speeddating.vim](https://github.com/tpope/vim-speeddating)
|
||||
* [unimpaired.vim](https://github.com/tpope/vim-unimpaired)
|
||||
* [vim-easyclip](https://github.com/svermeulen/vim-easyclip)
|
||||
* [vim-radical](https://github.com/glts/vim-radical)
|
||||
|
||||
Adding support to a plugin is generally as simple as the following
|
||||
command at the end of your map functions.
|
||||
|
||||
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
|
||||
|
||||
## Installation
|
||||
|
||||
Install using your favorite package manager, or use Vim's built-in package
|
||||
support:
|
||||
|
||||
mkdir -p ~/.vim/pack/tpope/start
|
||||
cd ~/.vim/pack/tpope/start
|
||||
git clone https://tpope.io/vim/repeat.git
|
||||
|
||||
## Contributing
|
||||
|
||||
See the contribution guidelines for
|
||||
[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
|
||||
|
||||
## Self-Promotion
|
||||
|
||||
Like repeat.vim? Follow the repository on
|
||||
[GitHub](https://github.com/tpope/vim-repeat) and vote for it on
|
||||
[vim.org](http://www.vim.org/scripts/script.php?script_id=2136). And if
|
||||
you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
|
||||
[Twitter](http://twitter.com/tpope) and
|
||||
[GitHub](https://github.com/tpope).
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
||||
See `:help license`.
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
" repeat.vim - Let the repeat command repeat plugin maps
|
||||
" Maintainer: Tim Pope
|
||||
" Version: 1.0
|
||||
" Version: 1.2
|
||||
" GetLatestVimScripts: 2136 1 :AutoInstall: repeat.vim
|
||||
|
||||
" Installation:
|
||||
" Place in either ~/.vim/plugin/repeat.vim (to load at start up) or
|
||||
" ~/.vim/autoload/repeat.vim (to load automatically as needed).
|
||||
"
|
||||
" License:
|
||||
" Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
||||
" See :help license
|
||||
"
|
||||
" Developers:
|
||||
" Basic usage is as follows:
|
||||
"
|
||||
|
|
@ -24,44 +29,123 @@
|
|||
"
|
||||
" Make sure to call the repeat#set function _after_ making changes to the
|
||||
" file.
|
||||
"
|
||||
" For mappings that use a register and want the same register used on
|
||||
" repetition, use:
|
||||
"
|
||||
" silent! call repeat#setreg("\<Plug>MappingToRepeatCommand", v:register)
|
||||
"
|
||||
" This function can (and probably needs to be) called before making changes to
|
||||
" the file (as those typically clear v:register). Therefore, the call sequence
|
||||
" in your mapping will look like this:
|
||||
"
|
||||
" nnoremap <silent> <Plug>MyMap
|
||||
" \ :<C-U>execute 'silent! call repeat#setreg("\<lt>Plug>MyMap", v:register)'<Bar>
|
||||
" \ call <SID>MyFunction(v:register, ...)<Bar>
|
||||
" \ silent! call repeat#set("\<lt>Plug>MyMap")<CR>
|
||||
|
||||
if exists("g:loaded_repeat") || &cp || v:version < 700
|
||||
if exists("g:loaded_repeat") || &cp || v:version < 800
|
||||
finish
|
||||
endif
|
||||
let g:loaded_repeat = 1
|
||||
|
||||
let g:repeat_tick = -1
|
||||
let g:repeat_reg = ['', '']
|
||||
|
||||
" Special function to avoid spurious repeats in a related, naturally repeating
|
||||
" mapping when your repeatable mapping doesn't increase b:changedtick.
|
||||
function! repeat#invalidate()
|
||||
autocmd! repeat_custom_motion
|
||||
let g:repeat_tick = -1
|
||||
endfunction
|
||||
|
||||
function! repeat#set(sequence,...)
|
||||
silent exe "norm! \"=''\<CR>p"
|
||||
let g:repeat_sequence = a:sequence
|
||||
let g:repeat_count = a:0 ? a:1 : v:count
|
||||
let g:repeat_tick = b:changedtick
|
||||
augroup repeat_custom_motion
|
||||
autocmd!
|
||||
autocmd CursorMoved <buffer> let g:repeat_tick = b:changedtick | autocmd! repeat_custom_motion
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
function! s:repeat(count)
|
||||
if g:repeat_tick == b:changedtick
|
||||
let c = g:repeat_count
|
||||
let s = g:repeat_sequence
|
||||
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
|
||||
call feedkeys(cnt . s)
|
||||
function! repeat#setreg(sequence,register)
|
||||
let g:repeat_reg = [a:sequence, a:register]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:default_register()
|
||||
let values = split(&clipboard, ',')
|
||||
if index(values, 'unnamedplus') != -1
|
||||
return '+'
|
||||
elseif index(values, 'unnamed') != -1
|
||||
return '*'
|
||||
else
|
||||
call feedkeys((a:count ? a:count : '') . '.', 'n')
|
||||
return '"'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:wrap(command,count)
|
||||
let preserve = (g:repeat_tick == b:changedtick)
|
||||
exe 'norm! '.(a:count ? a:count : '').a:command
|
||||
if preserve
|
||||
let g:repeat_tick = b:changedtick
|
||||
endif
|
||||
function! repeat#run(count)
|
||||
let s:errmsg = ''
|
||||
try
|
||||
if g:repeat_tick == b:changedtick
|
||||
let r = ''
|
||||
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
|
||||
" Take the original register, unless another (non-default, we
|
||||
" unfortunately cannot detect no vs. a given default register)
|
||||
" register has been supplied to the repeat command (as an
|
||||
" explicit override).
|
||||
let regname = v:register ==# s:default_register() ? g:repeat_reg[1] : v:register
|
||||
if regname ==# '='
|
||||
" This causes a re-evaluation of the expression on repeat, which
|
||||
" is what we want.
|
||||
let r = '"=' . getreg('=', 1) . "\<CR>"
|
||||
else
|
||||
let r = '"' . regname
|
||||
endif
|
||||
endif
|
||||
|
||||
let c = g:repeat_count
|
||||
let s = g:repeat_sequence
|
||||
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
|
||||
call feedkeys(s, 'i')
|
||||
call feedkeys(r . cnt, 'ni')
|
||||
else
|
||||
call feedkeys((a:count ? a:count : '') . '.', 'ni')
|
||||
endif
|
||||
catch /^Vim(normal):/
|
||||
let s:errmsg = v:errmsg
|
||||
return 0
|
||||
endtry
|
||||
return 1
|
||||
endfunction
|
||||
function! repeat#errmsg()
|
||||
return s:errmsg
|
||||
endfunction
|
||||
|
||||
nnoremap <silent> . :<C-U>call <SID>repeat(v:count)<CR>
|
||||
nnoremap <silent> u :<C-U>call <SID>wrap('u',v:count)<CR>
|
||||
nnoremap <silent> U :<C-U>call <SID>wrap('U',v:count)<CR>
|
||||
nnoremap <silent> <C-R> :<C-U>call <SID>wrap("\<Lt>C-R>",v:count)<CR>
|
||||
function! repeat#wrap(command,count)
|
||||
let foldopen = &foldopen =~# 'undo\|all' ? 'zv' : ''
|
||||
let preserve = g:repeat_tick == b:changedtick ? ":let g:repeat_tick = b:changedtick\r" : ''
|
||||
return (a:count ? a:count : '') . a:command . preserve . foldopen
|
||||
endfunction
|
||||
|
||||
nnoremap <silent> <Plug>(RepeatDot) :<C-U>if !repeat#run(v:count)<Bar>echoerr repeat#errmsg()<Bar>endif<CR>
|
||||
nmap <silent><expr><script> <Plug>(RepeatUndo) repeat#wrap('u',v:count)
|
||||
nmap <silent><expr><script> <Plug>(RepeatUndoLine) repeat#wrap('U',v:count)
|
||||
nmap <silent><expr><script> <Plug>(RepeatRedo) repeat#wrap("\022",v:count)
|
||||
|
||||
if !hasmapto('<Plug>(RepeatDot)', 'n')
|
||||
nmap . <Plug>(RepeatDot)
|
||||
endif
|
||||
if !hasmapto('<Plug>(RepeatUndo)', 'n')
|
||||
nmap u <Plug>(RepeatUndo)
|
||||
endif
|
||||
if maparg('U','n') ==# '' && !hasmapto('<Plug>(RepeatUndoLine)', 'n')
|
||||
nmap U <Plug>(RepeatUndoLine)
|
||||
endif
|
||||
if !hasmapto('<Plug>(RepeatRedo)', 'n')
|
||||
nmap <C-R> <Plug>(RepeatRedo)
|
||||
endif
|
||||
|
||||
augroup repeatPlugin
|
||||
autocmd!
|
||||
|
|
|
|||
Loading…
Reference in a new issue