From e098f748820a659336510f007f1e2f9715966908 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 2 Oct 2013 01:07:59 +0900 Subject: [PATCH] Remove a blank line when a regtype is 'V' and a text object is entire buffer When a regtype is 'V' and the object is entire buffer, a blank line remains at the top of buffer because a buffer of Vim has at least one line for the place of cursor. This commit fixes the issue by dirty workaround. --- autoload/operator/replace.vim | 8 ++++++++ t/entire_buffer.vim | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 t/entire_buffer.vim diff --git a/autoload/operator/replace.vim b/autoload/operator/replace.vim index 42a9d75..bbd48c7 100644 --- a/autoload/operator/replace.vim +++ b/autoload/operator/replace.vim @@ -42,6 +42,14 @@ function! operator#replace#do(motion_wise) "{{{2 let original_selection = &g:selection let &g:selection = 'inclusive' execute 'normal!' '`['.visual_command.'`]"_d' + + " Work around + " When regtype is linewise and text object is entire buffer, remove + " blank line after pasting + if getregtype(register) ==# 'V' && getline(1, '$') == [''] + let put_command .= '`[k"_dd' + endif + let &g:selection = original_selection end execute 'normal!' '"'.register.put_command diff --git a/t/entire_buffer.vim b/t/entire_buffer.vim new file mode 100644 index 0000000..2ddd0f9 --- /dev/null +++ b/t/entire_buffer.vim @@ -0,0 +1,19 @@ +runtime! plugin/operator/*.vim + +describe '(operator-replace)' + before + new + call setline(1, 'hoge huga poyo') + end + + after + close! + end + + it 'works properly when regtype is V and object is entire buffer' + call setreg('s', 'piyo poyo', 'V') + execute 'normal' "V\"s\(operator-replace)" + Expect line('$') == 1 + Expect getline(1) ==# 'piyo poyo' + end +end