mirror of
https://github.com/tpope/vim-repeat.git
synced 2026-09-10 15:26:24 -04:00
Compare commits
15 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65846025c1 | ||
|
|
5bd4c87a14 | ||
|
|
a89a4d0760 | ||
|
|
4bac219cc0 | ||
|
|
8b4435c5bb | ||
|
|
e0466d2b24 | ||
|
|
24afe922e6 | ||
|
|
c947ad2b6a | ||
|
|
ae361bea99 | ||
|
|
0b9b5e742f | ||
|
|
5974ea07ac | ||
|
|
eb97e729be | ||
|
|
43d2678fa5 | ||
|
|
1ea8a5325b | ||
|
|
8fe8bde4f4 |
|
|
@ -1,5 +1,4 @@
|
||||||
repeat.vim
|
# repeat.vim
|
||||||
==========
|
|
||||||
|
|
||||||
If you've ever tried using the `.` command after a plugin map, you were
|
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
|
likely disappointed to discover it only repeated the last native command
|
||||||
|
|
@ -11,34 +10,30 @@ The following plugins support repeat.vim:
|
||||||
|
|
||||||
* [surround.vim](https://github.com/tpope/vim-surround)
|
* [surround.vim](https://github.com/tpope/vim-surround)
|
||||||
* [speeddating.vim](https://github.com/tpope/vim-speeddating)
|
* [speeddating.vim](https://github.com/tpope/vim-speeddating)
|
||||||
* [abolish.vim](https://github.com/tpope/vim-abolish)
|
|
||||||
* [unimpaired.vim](https://github.com/tpope/vim-unimpaired)
|
* [unimpaired.vim](https://github.com/tpope/vim-unimpaired)
|
||||||
* [commentary.vim](https://github.com/tpope/vim-commentary)
|
|
||||||
* [vim-easyclip](https://github.com/svermeulen/vim-easyclip)
|
* [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
|
Adding support to a plugin is generally as simple as the following
|
||||||
command at the end of your map functions.
|
command at the end of your map functions.
|
||||||
|
|
||||||
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
|
silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
|
||||||
|
|
||||||
Installation
|
## Installation
|
||||||
------------
|
|
||||||
|
|
||||||
If you don't have a preferred installation method, I recommend
|
Install using your favorite package manager, or use Vim's built-in package
|
||||||
installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
|
support:
|
||||||
then simply copy and paste:
|
|
||||||
|
|
||||||
cd ~/.vim/bundle
|
mkdir -p ~/.vim/pack/tpope/start
|
||||||
git clone git://github.com/tpope/vim-repeat.git
|
cd ~/.vim/pack/tpope/start
|
||||||
|
git clone https://tpope.io/vim/repeat.git
|
||||||
|
|
||||||
Contributing
|
## Contributing
|
||||||
------------
|
|
||||||
|
|
||||||
See the contribution guidelines for
|
See the contribution guidelines for
|
||||||
[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
|
[pathogen.vim](https://github.com/tpope/vim-pathogen#readme).
|
||||||
|
|
||||||
Self-Promotion
|
## Self-Promotion
|
||||||
--------------
|
|
||||||
|
|
||||||
Like repeat.vim? Follow the repository on
|
Like repeat.vim? Follow the repository on
|
||||||
[GitHub](https://github.com/tpope/vim-repeat) and vote for it on
|
[GitHub](https://github.com/tpope/vim-repeat) and vote for it on
|
||||||
|
|
@ -47,8 +42,7 @@ you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
|
||||||
[Twitter](http://twitter.com/tpope) and
|
[Twitter](http://twitter.com/tpope) and
|
||||||
[GitHub](https://github.com/tpope).
|
[GitHub](https://github.com/tpope).
|
||||||
|
|
||||||
License
|
## License
|
||||||
-------
|
|
||||||
|
|
||||||
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
||||||
See `:help license`.
|
See `:help license`.
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,11 @@
|
||||||
" in your mapping will look like this:
|
" in your mapping will look like this:
|
||||||
"
|
"
|
||||||
" nnoremap <silent> <Plug>MyMap
|
" nnoremap <silent> <Plug>MyMap
|
||||||
" \ :<C-U>silent! call repeat#setreg("\<lt>Plug>MyMap", v:register)<Bar>
|
" \ :<C-U>execute 'silent! call repeat#setreg("\<lt>Plug>MyMap", v:register)'<Bar>
|
||||||
" \ call <SID>MyFunction(v:register, ...)<Bar>
|
" \ call <SID>MyFunction(v:register, ...)<Bar>
|
||||||
" \ silent! call repeat#set("\<lt>Plug>MyMap")<CR>
|
" \ 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
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_repeat = 1
|
let g:loaded_repeat = 1
|
||||||
|
|
@ -73,55 +73,66 @@ function! repeat#setreg(sequence,register)
|
||||||
let g:repeat_reg = [a:sequence, a:register]
|
let g:repeat_reg = [a:sequence, a:register]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! s:default_register()
|
||||||
|
let values = split(&clipboard, ',')
|
||||||
|
if index(values, 'unnamedplus') != -1
|
||||||
|
return '+'
|
||||||
|
elseif index(values, 'unnamed') != -1
|
||||||
|
return '*'
|
||||||
|
else
|
||||||
|
return '"'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! repeat#run(count)
|
function! repeat#run(count)
|
||||||
|
let s:errmsg = ''
|
||||||
try
|
try
|
||||||
if g:repeat_tick == b:changedtick
|
if g:repeat_tick == b:changedtick
|
||||||
let r = ''
|
let r = ''
|
||||||
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
|
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
|
||||||
if 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
|
" This causes a re-evaluation of the expression on repeat, which
|
||||||
" is what we want.
|
" is what we want.
|
||||||
let r = '"=' . getreg('=', 1) . "\<CR>"
|
let r = '"=' . getreg('=', 1) . "\<CR>"
|
||||||
else
|
else
|
||||||
let r = '"' . g:repeat_reg[1]
|
let r = '"' . regname
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let c = g:repeat_count
|
let c = g:repeat_count
|
||||||
let s = g:repeat_sequence
|
let s = g:repeat_sequence
|
||||||
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
|
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
|
||||||
if ((v:version == 703 && has('patch100')) || (v:version == 704 && !has('patch601')))
|
call feedkeys(s, 'i')
|
||||||
exe 'norm ' . r . cnt . s
|
call feedkeys(r . cnt, 'ni')
|
||||||
else
|
|
||||||
call feedkeys(s, 'i')
|
|
||||||
call feedkeys(r . cnt, 'ni')
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
if ((v:version == 703 && has('patch100')) || (v:version == 704 && !has('patch601')))
|
call feedkeys((a:count ? a:count : '') . '.', 'ni')
|
||||||
exe 'norm! '.(a:count ? a:count : '') . '.'
|
|
||||||
else
|
|
||||||
call feedkeys((a:count ? a:count : '') . '.', 'ni')
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
catch /^Vim(normal):/
|
catch /^Vim(normal):/
|
||||||
return 'echoerr v:errmsg'
|
let s:errmsg = v:errmsg
|
||||||
|
return 0
|
||||||
endtry
|
endtry
|
||||||
return ''
|
return 1
|
||||||
|
endfunction
|
||||||
|
function! repeat#errmsg()
|
||||||
|
return s:errmsg
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! repeat#wrap(command,count)
|
function! repeat#wrap(command,count)
|
||||||
let preserve = (g:repeat_tick == b:changedtick)
|
let foldopen = &foldopen =~# 'undo\|all' ? 'zv' : ''
|
||||||
call feedkeys((a:count ? a:count : '').a:command, 'n')
|
let preserve = g:repeat_tick == b:changedtick ? ":let g:repeat_tick = b:changedtick\r" : ''
|
||||||
exe (&foldopen =~# 'undo\|all' ? 'norm! zv' : '')
|
return (a:count ? a:count : '') . a:command . preserve . foldopen
|
||||||
if preserve
|
|
||||||
let g:repeat_tick = b:changedtick
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
nnoremap <silent> <Plug>(RepeatDot) :<C-U>exe repeat#run(v:count)<CR>
|
nnoremap <silent> <Plug>(RepeatDot) :<C-U>if !repeat#run(v:count)<Bar>echoerr repeat#errmsg()<Bar>endif<CR>
|
||||||
nnoremap <silent> <Plug>(RepeatUndo) :<C-U>call repeat#wrap('u',v:count)<CR>
|
nmap <silent><expr><script> <Plug>(RepeatUndo) repeat#wrap('u',v:count)
|
||||||
nnoremap <silent> <Plug>(RepeatUndoLine) :<C-U>call repeat#wrap('U',v:count)<CR>
|
nmap <silent><expr><script> <Plug>(RepeatUndoLine) repeat#wrap('U',v:count)
|
||||||
nnoremap <silent> <Plug>(RepeatRedo) :<C-U>call repeat#wrap("\<Lt>C-R>",v:count)<CR>
|
nmap <silent><expr><script> <Plug>(RepeatRedo) repeat#wrap("\022",v:count)
|
||||||
|
|
||||||
if !hasmapto('<Plug>(RepeatDot)', 'n')
|
if !hasmapto('<Plug>(RepeatDot)', 'n')
|
||||||
nmap . <Plug>(RepeatDot)
|
nmap . <Plug>(RepeatDot)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue