Skip to content

Commit

Permalink
Improved pasting with a count
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Mar 16, 2013
1 parent f6dd399 commit eebcf99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
14 changes: 7 additions & 7 deletions autoload/whitespaste.vim
Expand Up @@ -187,19 +187,19 @@ function! s:Paste(command)
let original_value = getreg(default_register, 1)
let original_type = getregtype(default_register)

call setreg(default_register, getreg(v:register, 1), getregtype(v:register))

if v:count >= 1
" we've been given a count, repeat v:count times
let repeat = v:count
let times = v:count
else
" no count, just run once
let repeat = 1
let times = 1
endif

for i in range(repeat)
exe a:command
endfor
let value = getreg(v:register, 1)
let value = repeat(value, times)
call setreg(default_register, value, getregtype(v:register))

exe a:command

call setreg(default_register, original_value, original_type)
endfunction
Expand Down
27 changes: 25 additions & 2 deletions spec/plugin/compatibility_spec.rb
Expand Up @@ -4,18 +4,41 @@
let(:filename) { 'test.txt' }
let(:vim) { @vim }

it "respects pasting with a count" do
it "respects pasting after with a count" do
set_file_contents <<-EOF
one
two
EOF

vim.command("call feedkeys('yy2p')")
vim.command("call feedkeys('yj2p')")
vim.write

assert_file_contents <<-EOF
one
one
two
one
two
two
EOF
end

it "respects pasting before with a count" do
set_file_contents <<-EOF
one
two
EOF

vim.command("call feedkeys('yj2P')")
vim.write

assert_file_contents <<-EOF
one
two
one
two
one
two
EOF
end

Expand Down

0 comments on commit eebcf99

Please sign in to comment.