Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make it possible to use different registers

Also, time to switch to a GUI Vimrunner. Headless one seems to hang at
some point again...
  • Loading branch information...
commit 65ff89aa6aaeb217fcec46ad00c13b09ea4772fa 1 parent 1f07095
@AndrewRadev authored
View
22 autoload/whitespaste.vim
@@ -1,7 +1,7 @@
function! whitespaste#Paste(normal_command)
- if getregtype() == 'V'
+ if getregtype(v:register) == 'V'
call whitespaste#PasteLinewise(a:normal_command)
- elseif getregtype() == 'v'
+ elseif getregtype(v:register) == 'v'
call whitespaste#PasteCharwise(a:normal_command)
else
call whitespaste#PasteBlockwise(a:normal_command)
@@ -163,5 +163,23 @@ function! whitespaste#SetBlankLines(start, end, line_count)
endfunction
function! s:Paste(command)
+ let default_register = s:DefaultRegister()
+ let original_value = getreg(default_register, 1)
+ let original_type = getregtype(default_register)
+
+ call setreg(default_register, getreg(v:register, 1), getregtype(v:register))
+
exe a:command
+
+ call setreg(default_register, original_value, original_type)
+endfunction
+
+function! s:DefaultRegister()
+ if &clipboard =~ 'unnamedplus'
+ return '+'
+ elseif &clipboard =~ 'unnamed'
+ return '*'
+ else
+ return '"'
+ endif
endfunction
View
31 spec/plugin/different_registers_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe "Different registers" do
+ let(:filename) { 'test.txt' }
+ let(:vim) { @vim }
+
+ it "can use a register other than the default one" do
+ set_file_contents <<-EOF
+ one
+ two
+ EOF
+
+ vim.search('one').normal('V"ay')
+ vim.search('two').normal('V"by')
+
+ vim.normal('"ap').write
+ assert_file_contents <<-EOF
+ one
+ two
+ one
+ EOF
+
+ vim.normal('"bp').write
+ assert_file_contents <<-EOF
+ one
+ two
+ one
+ two
+ EOF
+ end
+end
View
2  spec/spec_helper.rb
@@ -7,7 +7,7 @@
config.include Support::Files
config.before(:suite) do
- VIM = Vimrunner.start
+ VIM = Vimrunner.start_gvim
VIM.add_plugin(File.expand_path('.'), 'plugin/whitespaste.vim')
Support::Vim.define_vim_methods(VIM)
end
Please sign in to comment.
Something went wrong with that request. Please try again.