Skip to content

Commit

Permalink
Version 1.21
Browse files Browse the repository at this point in the history
- 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
Ingo Karkat authored and vim-scripts committed Jun 18, 2012
1 parent 0799772 commit 46ba4bc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
18 changes: 9 additions & 9 deletions README
Expand Up @@ -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. or block-wise paste no matter how you yanked the text.


SOURCE SOURCE
Based on vimtip #1199 by cory, Based on vimtip #1199 by cory,
http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste     http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste


USAGE USAGE
["x]gcp Paste characterwise (newline characters are flattened ["x]gcp                 Paste characterwise (newline characters are flattened
["x]gcP to spaces) [count] times. ["x]gcP                 to spaces) [count] times.
["x]glp Paste linewise (even if yanked text is not a complete ["x]glp                 Paste linewise (even if yanked text is not a complete
["x]glP line) [count] times. ["x]glP                 line) [count] times.
["x]gbp Paste blockwise (inserting multiple lines in-place, ["x]gbp                 Paste blockwise (inserting multiple lines in-place,
["x]gbP pushing existing text further to the right) [count] ["x]gbP                 pushing existing text further to the right) [count]
times.                         times.
9 changes: 8 additions & 1 deletion doc/UnconditionalPaste.txt
Expand Up @@ -50,7 +50,7 @@ To uninstall, use the |:RmVimball| command.
DEPENDENCIES *UnconditionalPaste-dependencies* DEPENDENCIES *UnconditionalPaste-dependencies*


- Requires Vim 7.0 or higher. - Requires Vim 7.0 or higher.
- vimscript #2136 repeat.vim autoload script (optional). - repeat.vim (vimscript #2136) plugin (optional).


============================================================================== ==============================================================================
CONFIGURATION *UnconditionalPaste-configuration* CONFIGURATION *UnconditionalPaste-configuration*
Expand All @@ -77,6 +77,13 @@ IDEAS *UnconditionalPaste-ideas*
============================================================================== ==============================================================================
HISTORY *UnconditionalPaste-history* 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 1.20 30-Sep-2011
BUG: Repeat always used the unnamed register. Add register registration to BUG: Repeat always used the unnamed register. Add register registration to
enhanced repeat.vim plugin. This also handles repetition when used together enhanced repeat.vim plugin. This also handles repetition when used together
Expand Down
25 changes: 23 additions & 2 deletions plugin/UnconditionalPaste.vim
Expand Up @@ -13,6 +13,13 @@
" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste " http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
" "
" REVISION DATE REMARKS " 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. " 1.20.012 29-Sep-2011 BUG: Repeat always used the unnamed register.
" Add register registration to enhanced repeat.vim " Add register registration to enhanced repeat.vim
" plugin, which also handles repetition when used " plugin, which also handles repetition when used
Expand Down Expand Up @@ -66,7 +73,10 @@ endfunction
function! s:Flatten( text ) function! s:Flatten( text )
" Remove newline characters at the end of the text, convert all other " Remove newline characters at the end of the text, convert all other
" newlines to a single space. " 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 endfunction


function! s:Paste( regName, pasteType, pasteCmd ) function! s:Paste( regName, pasteType, pasteCmd )
Expand All @@ -91,7 +101,18 @@ function! s:Paste( regName, pasteType, pasteCmd )
endif endif


try 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 execute 'normal! "' . l:regName . (v:count ? v:count : '') . a:pasteCmd
call setreg(l:regName, l:regContent, l:regType) call setreg(l:regName, l:regContent, l:regType)
catch /^Vim\%((\a\+)\)\=:E/ catch /^Vim\%((\a\+)\)\=:E/
Expand Down

0 comments on commit 46ba4bc

Please sign in to comment.