From 172fbc5f7e346c26c3cc64335de1e33347f79058 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 22 Aug 2018 22:16:07 +1200 Subject: First version --- README.md | 18 ++++++++++++++++++ VERSION | 1 + autoload/replace_operator.vim | 13 +++++++++++++ doc/replace_operator.txt | 35 +++++++++++++++++++++++++++++++++++ plugin/replace_operator.vim | 22 ++++++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 README.md create mode 100644 VERSION create mode 100644 autoload/replace_operator.vim create mode 100644 doc/replace_operator.txt create mode 100644 plugin/replace_operator.vim 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/ diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -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 ==# "\" + 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* + + *(RepeatOperator)* +The normal and visual mode mapping targets are both named +|(RepeatOperator)|. There is no default key mapping; you should define +one yourself in your |vimrc|. For example: +> + nmap r (ReplaceOperator) + xmap r (ReplaceOperator) +< +AUTHOR *replace_operator-author* + +Written and maintained by Tom Ryder . + +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 +" 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 + \ (ReplaceOperator) + \ :set operatorfunc=replace_operator#Operatorfuncg@ +xnoremap + \ (ReplaceOperator) + \ :call replace_operator#Operatorfunc(visualmode()) -- cgit v1.2.3