Skip to content
Browse files

Pasting with a count

  • Loading branch information...
1 parent 1acaa09 commit 2ff5d113621967ef5e69d9c5150d2c06ec51334d @AndrewRadev committed Feb 25, 2013
Showing with 34 additions and 3 deletions.
  1. +11 −1 autoload/whitespaste.vim
  2. +2 −2 plugin/whitespaste.vim
  3. +21 −0 spec/plugin/compatibility_spec.rb
View
12 autoload/whitespaste.vim
@@ -189,7 +189,17 @@ function! s:Paste(command)
call setreg(default_register, getreg(v:register, 1), getregtype(v:register))
- exe a:command
+ if v:count >= 1
+ " we've been given a count, repeat v:count times
+ let repeat = v:count
+ else
+ " no count, just run once
+ let repeat = 1
+ endif
+
+ for i in range(repeat)
+ exe a:command
+ endfor
call setreg(default_register, original_value, original_type)
endfunction
View
4 plugin/whitespaste.vim
@@ -75,8 +75,8 @@ autocmd FileType html,php,eruby,eco let b:whitespaste_linewise_definitions = {
\ ]
\ }
-command! WhitespasteBefore call whitespaste#Paste(g:whitespaste_paste_before_command)
-command! WhitespasteAfter call whitespaste#Paste(g:whitespaste_paste_after_command)
+command! -count WhitespasteBefore call whitespaste#Paste(g:whitespaste_paste_before_command)
+command! -count WhitespasteAfter call whitespaste#Paste(g:whitespaste_paste_after_command)
command! -range WhitespasteVisual call whitespaste#Paste(g:whitespaste_paste_visual_command)
nmap <Plug>WhitespasteBefore :WhitespasteBefore<cr>
View
21 spec/plugin/compatibility_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe "compatibility with normal pasting" do
+ let(:filename) { 'test.txt' }
+ let(:vim) { @vim }
+
+ it "respects pasting with a count" do
+ set_file_contents <<-EOF
+ one
+ EOF
+
+ vim.command("call feedkeys('yy2p')")
+ vim.write
+
+ assert_file_contents <<-EOF
+ one
+ one
+ one
+ EOF
+ end
+end

0 comments on commit 2ff5d11

Please sign in to comment.
Something went wrong with that request. Please try again.