From 20d1d12f9be57e60e4998f3680716afdb7b435e6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 13 Jul 2018 22:25:17 +1200 Subject: Refactor to use 'operatorfunc' with autoload This removes the repeat.vim dependency for repeats. --- README.md | 11 +++++------ autoload/put_blank_lines.vim | 19 +++++++++++++++++++ doc/put_blank_lines.txt | 13 ++++++------- plugin/put_blank_lines.vim | 34 ++++++---------------------------- 4 files changed, 36 insertions(+), 41 deletions(-) create mode 100644 autoload/put_blank_lines.vim diff --git a/README.md b/README.md index 993e93b..1533438 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,12 @@ put\_blank\_lines.vim ===================== This plugin provides mapping targets for inserting blank lines above or below -the current line without going into insert mode. The applicable code is lifted -from [unimpaired.vim][1]. It still works with [repeat.vim][2], if that's -installed, to make the mappings repeatable. +the current line without going into insert mode, including count prefixes and +repeating with the dot command. -I wrote this because I used these mappings from the original plugin frequently, -but (almost) nothing else from it. The only functional difference is that the -number of added lines is not reported, via a `:silent` suppression. +The idea and insert method is lifted from the same mappings for +[unimpaired.vim][1], but called with `'operatorfunc'` to allow counts and +repeating without requiring [repeat.vim][2]. Configuration ------------- diff --git a/autoload/put_blank_lines.vim b/autoload/put_blank_lines.vim new file mode 100644 index 0000000..c0c835d --- /dev/null +++ b/autoload/put_blank_lines.vim @@ -0,0 +1,19 @@ +function! put_blank_lines#Above(count) + set operatorfunc=put_blank_lines#AboveOpfunc + call feedkeys(a:count.'g@l', 'n') +endfunction + +function! put_blank_lines#Below(count) + set operatorfunc=put_blank_lines#BelowOpfunc + call feedkeys(a:count.'g@l', 'n') +endfunction + +function! put_blank_lines#AboveOpfunc(type) + silent put! =repeat(nr2char(10), v:count1) + ']+1 +endfunction + +function! put_blank_lines#BelowOpfunc(type) + silent put =repeat(nr2char(10), v:count1) + '[-1 +endfunction diff --git a/doc/put_blank_lines.txt b/doc/put_blank_lines.txt index b50fd18..38c6b7a 100644 --- a/doc/put_blank_lines.txt +++ b/doc/put_blank_lines.txt @@ -1,15 +1,14 @@ -*put_blank_lines.txt* For Vim version 6.0 Last change: 2018 June 17 +*put_blank_lines.txt* For Vim version 7.0 Last change: 2018 July 13 DESCRIPTION *put_blank_lines* This plugin provides mapping targets for inserting blank lines above or below -the current line without going into insert mode. The applicable code is lifted -from unimpaired.vim. It still works with repeat.vim, if that's installed, to -make the mappings repeatable. +the current line without going into insert mode, including count prefixes and +repeating with the dot command. -I wrote this because I used these mappings from the original plugin frequently, -but (almost) nothing else from it. The only functional difference is that the -number of added lines is not reported, via a `:silent` suppression. +The idea and insert method is lifted from the same mappings for +unimpaired.vim, but called with `'operatorfunc'` to allow counts and repeating +without requiring repeat.vim. CONFIGURATION *put_blank_lines-configuration* diff --git a/plugin/put_blank_lines.vim b/plugin/put_blank_lines.vim index b64fb0b..ede964a 100644 --- a/plugin/put_blank_lines.vim +++ b/plugin/put_blank_lines.vim @@ -1,7 +1,6 @@ " " put_blank_lines.vim: Provide plugin maps to put blank lines above or below -" the current line. The guts of this is backported from Tim Pope's -" unimpaired.vim plugin, and still uses repeat.vim if it can find it. +" the current line. " " Author: Tom Ryder " License: Same as Vim itself @@ -9,35 +8,14 @@ if exists('g:loaded_put_blank_lines') || &compatible finish endif -if v:version < 600 +if v:version < 700 finish endif let g:loaded_put_blank_lines = 1 -function! s:PutBlankLinesAbove(count) - let l:i = 0 - while l:i < a:count - silent put! =nr2char(10) - let l:i = l:i + 1 - ']+1 - endwhile - silent! call repeat#set("\(PutBlankLinesAbove)", a:count) -endfunction - -function! s:PutBlankLinesBelow(count) - let l:i = 0 - while l:i < a:count - silent put =nr2char(10) - let l:i = l:i + 1 - '[-1 - endwhile - silent! call repeat#set("\(PutBlankLinesBelow)", a:count) -endfunction - -nnoremap - \ (PutBlankLinesAbove) - \ :call PutBlankLinesAbove(v:count1) - nnoremap \ (PutBlankLinesBelow) - \ :call PutBlankLinesBelow(v:count1) + \ :call put_blank_lines#Below(v:count1) +nnoremap + \ (PutBlankLinesAbove) + \ :call put_blank_lines#Above(v:count1) -- cgit v1.2.3 From 8ab5b152aa680af40cf930616a12d58bc5856633 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 13 Jul 2018 22:26:20 +1200 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7dea76e..227cea2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.1 +2.0.0 -- cgit v1.2.3