Browse files

Version 1.21

- ENH: When pasting a blockwise register as lines, strip all trailing whitespace. This is useful when cutting a block of text from a column-like text and pasting as new lines.  
- ENH: When pasting a blockwise register as characters, flatten and shrink all trailing whitespace to a single space.
  • Loading branch information...
1 parent 0799772 commit 46ba4bcf3af507948f8d79de647cd57d8fe11055 Ingo Karkat committed with Jun 17, 2012
Showing with 40 additions and 12 deletions.
  1. +9 −9 README
  2. +8 −1 doc/UnconditionalPaste.txt
  3. +23 −2 plugin/UnconditionalPaste.vim
View
18 README
@@ -7,14 +7,14 @@ The mappings defined by this plugin will allow you to do a character-, line-,
or block-wise paste no matter how you yanked the text.
SOURCE
-Based on vimtip #1199 by cory,
- http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
+Based on vimtip #1199 by cory,
+    http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
USAGE
-["x]gcp Paste characterwise (newline characters are flattened
-["x]gcP to spaces) [count] times.
-["x]glp Paste linewise (even if yanked text is not a complete
-["x]glP line) [count] times.
-["x]gbp Paste blockwise (inserting multiple lines in-place,
-["x]gbP pushing existing text further to the right) [count]
- times.
+["x]gcp                 Paste characterwise (newline characters are flattened
+["x]gcP                 to spaces) [count] times.
+["x]glp                 Paste linewise (even if yanked text is not a complete
+["x]glP                 line) [count] times.
+["x]gbp                 Paste blockwise (inserting multiple lines in-place,
+["x]gbP                 pushing existing text further to the right) [count]
+                        times.
View
9 doc/UnconditionalPaste.txt
@@ -50,7 +50,7 @@ To uninstall, use the |:RmVimball| command.
DEPENDENCIES *UnconditionalPaste-dependencies*
- Requires Vim 7.0 or higher.
-- vimscript #2136 repeat.vim autoload script (optional).
+- repeat.vim (vimscript #2136) plugin (optional).
==============================================================================
CONFIGURATION *UnconditionalPaste-configuration*
@@ -77,6 +77,13 @@ IDEAS *UnconditionalPaste-ideas*
==============================================================================
HISTORY *UnconditionalPaste-history*
+1.21 02-Dec-2011
+- ENH: When pasting a blockwise register as lines, strip all trailing
+ whitespace. This is useful when cutting a block of text from a column-like
+ text and pasting as new lines.
+- ENH: When pasting a blockwise register as characters, flatten and shrink all
+ trailing whitespace to a single space.
+
1.20 30-Sep-2011
BUG: Repeat always used the unnamed register. Add register registration to
enhanced repeat.vim plugin. This also handles repetition when used together
View
25 plugin/UnconditionalPaste.vim
@@ -13,6 +13,13 @@
" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
"
" REVISION DATE REMARKS
+" 1.21.013 02-Dec-2011 ENH: When pasting a blockwise register as lines,
+" strip all trailing whitespace. This is useful
+" when cutting a block of text from a column-like
+" text and pasting as new lines.
+" ENH: When pasting a blockwise register as
+" characters, flatten and shrink all trailing
+" whitespace to a single space.
" 1.20.012 29-Sep-2011 BUG: Repeat always used the unnamed register.
" Add register registration to enhanced repeat.vim
" plugin, which also handles repetition when used
@@ -66,7 +73,10 @@ endfunction
function! s:Flatten( text )
" Remove newline characters at the end of the text, convert all other
" newlines to a single space.
- return substitute(substitute(a:text, "\n\\+$", '', 'g'), "\n\\+", ' ', 'g')
+ return substitute(substitute(a:text, '\n\+$', '', 'g'), '\n\+', ' ', 'g')
+endfunction
+function! s:StripTrailingWhitespace( text )
+ return substitute(a:text, '\s\+\ze\(\n\|$\)', '', 'g')
endfunction
function! s:Paste( regName, pasteType, pasteCmd )
@@ -91,7 +101,18 @@ function! s:Paste( regName, pasteType, pasteCmd )
endif
try
- call setreg(l:regName, (a:pasteType ==# 'c' ? s:Flatten(l:regContent) : l:regContent), a:pasteType)
+ let l:pasteContent = l:regContent
+ if a:pasteType ==# 'c'
+ if l:regType[0] ==# "\<C-v>"
+ let l:pasteContent = s:Flatten(s:StripTrailingWhitespace(l:regContent))
+ else
+ let l:pasteContent = s:Flatten(l:regContent)
+ endif
+ elseif a:pasteType ==# 'l' && l:regType[0] ==# "\<C-v>"
+ let l:pasteContent = s:StripTrailingWhitespace(l:regContent)
+ endif
+
+ call setreg(l:regName, l:pasteContent, a:pasteType)
execute 'normal! "' . l:regName . (v:count ? v:count : '') . a:pasteCmd
call setreg(l:regName, l:regContent, l:regType)
catch /^Vim\%((\a\+)\)\=:E/

0 comments on commit 46ba4bc

Please sign in to comment.