From f8a7ff54a4bde748a3321a582ec910e8302b6386 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 29 Dec 2018 23:28:21 +1300 Subject: Fix text replacement for Vim 7.1 through 7.3 --- autoload/replace_operator.vim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/autoload/replace_operator.vim b/autoload/replace_operator.vim index a48a04d..ff442b6 100644 --- a/autoload/replace_operator.vim +++ b/autoload/replace_operator.vim @@ -20,17 +20,23 @@ function! replace_operator#Operatorfunc(type) abort " Ensure that we include end-of-line and final characters in selections set selection=inclusive - " Select or re-select text, depending on how we were invoked + " Build normal mode keystrokes to select the operated text in visual mode if a:type ==# 'line' - normal! '[V'] + let l:select = '''[V'']' elseif a:type ==# 'block' - execute "normal! `[\`]" + let l:select = "`[\`]" else - normal! `[v`] + let l:select = '`[v`]' endif - " Re-select the text, and replace it with the contents of the register - execute 'normal! "'.l:register.'p' + " Build normal mode keystrokes to paste from the selected register; only add + " a register prefix if it's not the default unnamed register, because Vim + " before 7.4 gets ""p wrong in visual mode + let l:paste = 'p' + if l:register !=# '"' + let l:paste = '"'.l:register.l:paste + endif + silent execute 'normal! '.l:select.l:paste " Restore contents of the unnamed register and the previous values of the " 'clipboard' and 'selection' options -- cgit v1.2.3