diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-22 22:16:07 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-08-22 22:16:07 +1200 |
commit | 172fbc5f7e346c26c3cc64335de1e33347f79058 (patch) | |
tree | ca708bc0a32651ee3d400e819fbcd21dd30247f9 | |
download | vim-replace-operator-0.1.0.tar.gz (sig) vim-replace-operator-0.1.0.zip |
First versionv0.1.0
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | autoload/replace_operator.vim | 13 | ||||
-rw-r--r-- | doc/replace_operator.txt | 35 | ||||
-rw-r--r-- | plugin/replace_operator.vim | 22 |
5 files changed, 89 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..1496a8d --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +replace\_operator.vim +===================== + +This plugin provides normal and visual mode mapping targets to replace the text +bounded by a motion with the contents of a register, by default the unnamed +register. + +This allows you, for example, to select a set of lines and replace any other +set of lines with it in one repeatable operation. The text you replace stacks +up in the numbered registers as normal, if you do end up needing it back. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/replace_operator.vim b/autoload/replace_operator.vim new file mode 100644 index 0000000..c152657 --- /dev/null +++ b/autoload/replace_operator.vim @@ -0,0 +1,13 @@ +" Replace the operated text with the contents of a register +function! replace_operator#Operatorfunc(type) abort + let l:text = getreg() + if a:type ==# 'v' || a:type ==# 'V' || a:type ==# "\<C-V>" + normal! gvd + elseif a:type ==# 'line' + normal! `[V`]d + else + normal! `[v`]d + endif + call setreg(v:register, l:text) + normal! P +endfunction diff --git a/doc/replace_operator.txt b/doc/replace_operator.txt new file mode 100644 index 0000000..d8e6e18 --- /dev/null +++ b/doc/replace_operator.txt @@ -0,0 +1,35 @@ +*replace_operator.txt* For Vim version 7.0 Last change: 2018 Aug 22 + +DESCRIPTION *replace_operator* + +This plugin provides normal and visual mode mapping targets to replace the +text bounded by a motion with the contents of a register, by default the +unnamed register. + +This allows you, for example, to select a set of lines and replace any other +set of lines with it in one repeatable operation. The text you replace stacks +up in the numbered registers as normal, if you do end up needing it back. + +REQUIREMENTS *replace_operator-requirements* + +This plugin only loads if 'compatible' is not set. + +MAPPINGS *replace_operator-mappings* + + *<Plug>(RepeatOperator)* +The normal and visual mode mapping targets are both named +|<Plug>(RepeatOperator)|. There is no default key mapping; you should define +one yourself in your |vimrc|. For example: +> + nmap <Leader>r <Plug>(ReplaceOperator) + xmap <Leader>r <Plug>(ReplaceOperator) +< +AUTHOR *replace_operator-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *replace_operator-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/replace_operator.vim b/plugin/replace_operator.vim new file mode 100644 index 0000000..3e048d8 --- /dev/null +++ b/plugin/replace_operator.vim @@ -0,0 +1,22 @@ +" +" replace_operator.vim: Replace text selected with a motion with the +" contents of a register in a repeatable way. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('g:loaded_replace_operator') || &compatible + finish +endif +if v:version < 700 + finish +endif +let g:loaded_replace_operator = 1 + +" Set up mapping +nnoremap <silent> <unique> + \ <Plug>(ReplaceOperator) + \ :<C-U>set operatorfunc=replace_operator#Operatorfunc<CR>g@ +xnoremap <silent> <unique> + \ <Plug>(ReplaceOperator) + \ :<C-U>call replace_operator#Operatorfunc(visualmode())<CR> |