Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.10

Incorporated suggestions by Peter Rincker (thanks for the patch!):
- Made mappings configurable via the customary <Plug> mappings.
- Added mappings gbp, gbP for blockwise pasting.
- Now requires Vim version 7.0 or higher.
  • Loading branch information...
commit d123517417733f52d56f37355c976be6f986e499 1 parent 722f0d1
Ingo Karkat authored committed
Showing with 71 additions and 22 deletions.
  1. +7 −4 README
  2. +26 −8 doc/UnconditionalPaste.txt
  3. +38 −10 plugin/UnconditionalPaste.vim
View
11 README
@@ -11,7 +11,10 @@ Based on vimtip #1199 by cory,
http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
USAGE
-["x]glp Paste linewise (even if yanked text is not a complete
-["x]glP line) [count] times.
-["x]gcp Paste characterwise (newline characters are flattened to
-["x]gcP spaces) [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
34 doc/UnconditionalPaste.txt
@@ -26,11 +26,15 @@ Based on vimtip #1199 by cory,
==============================================================================
USAGE *UnconditionalPaste-usage*
+ *gcp* *gcP* *glp* *glP* *gbp* *gbP*
+["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]glp Paste linewise (even if yanked text is not a complete
-["x]glP line) [count] times.
-["x]gcp Paste characterwise (newline characters are flattened to
-["x]gcP spaces) [count] times.
==============================================================================
INSTALLATION *UnconditionalPaste-installation*
@@ -45,13 +49,21 @@ To uninstall, use the |:RmVimball| command.
DEPENDENCIES *UnconditionalPaste-dependencies*
-- Requires Vim 6.2 or higher.
+- Requires Vim 7.0 or higher.
==============================================================================
CONFIGURATION *UnconditionalPaste-configuration*
-Currently, the mappings are fixed and cannot be changed.
-
+If you want to use different mappings (e.g. starting with <Leader>), map your
+keys to the <Plug>UnconditionalPaste... mapping targets _before_ sourcing this
+script (e.g. in your |vimrc|): >
+ nmap <silent> <Leader>Pc <Plug>UnconditionalPasteCharBefore
+ nmap <silent> <Leader>pc <Plug>UnconditionalPasteCharAfter
+ nmap <silent> <Leader>Pl <Plug>UnconditionalPasteLineBefore
+ nmap <silent> <Leader>pl <Plug>UnconditionalPasteLineAfter
+ nmap <silent> <Leader>Pb <Plug>UnconditionalPasteBlockBefore
+ nmap <silent> <Leader>pb <Plug>UnconditionalPasteBlockAfter
+<
==============================================================================
LIMITATIONS *UnconditionalPaste-limitations*
@@ -64,6 +76,12 @@ IDEAS *UnconditionalPaste-ideas*
==============================================================================
HISTORY *UnconditionalPaste-history*
+1.10 12-Jan-2011
+Incorporated suggestions by Peter Rincker (thanks for the patch!):
+- Made mappings configurable via the customary <Plug> mappings.
+- Added mappings gbp, gbP for blockwise pasting.
+- Now requires Vim version 7.0 or higher.
+
1.00 10-Dec-2010
Published, prompted by a related question on reddit.
@@ -71,7 +89,7 @@ Published, prompted by a related question on reddit.
Started development, based on vimtip #1199 by cory.
==============================================================================
-Copyright: (C) 2006-2010 Ingo Karkat
+Copyright: (C) 2006-2011 Ingo Karkat
The VIM LICENSE applies to this script; see |copyright|.
Maintainer: Ingo Karkat <ingo@karkat.de>
View
48 plugin/UnconditionalPaste.vim
@@ -2,9 +2,9 @@
" how it was yanked.
"
" DEPENDENCIES:
-" - Requires Vim 6.2 or higher.
+" - Requires Vim 7.0 or higher.
-" Copyright: (C) 2006-2010 Ingo Karkat
+" Copyright: (C) 2006-2011 Ingo Karkat
" The VIM LICENSE applies to this script; see ':help copyright'.
"
" Maintainer: Ingo Karkat <ingo@karkat.de>
@@ -12,6 +12,12 @@
" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
"
" REVISION DATE REMARKS
+" 1.10.009 12-Jan-2011 Incorporated suggestions by Peter Rincker
+" (thanks for the patch!):
+" Made mappings configurable via the customary
+" <Plug> mappings.
+" Added mappings gbp, gbP for blockwise pasting.
+" Now requires Vim version 7.0 or higher.
" 1.00.008 10-Dec-2010 Prepared for publishing; find out lowest
" supported Vim version.
" 007 15-May-2009 Now catching and reporting any errors caused by
@@ -36,18 +42,21 @@
" 0.01 10-Apr-2006 file creation from vimtip #1199
" Avoid installing twice or when in unsupported Vim version.
-if exists('g:loaded_UnconditionalPaste') || (v:version < 602)
+if exists('g:loaded_UnconditionalPaste') || (v:version < 700)
finish
endif
let g:loaded_UnconditionalPaste = 1
-function! s:Flatten(text)
+let s:save_cpo = &cpo
+set cpo&vim
+
+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')
endfunction
-function! s:Paste(regName, pasteType, pasteCmd)
+function! s:Paste( regName, pasteType, pasteCmd )
try
let l:regType = getregtype(a:regName)
let l:regContent = getreg(a:regName)
@@ -55,18 +64,37 @@ function! s:Paste(regName, pasteType, pasteCmd)
execute 'normal! "' . a:regName . (v:count ? v:count : '') . a:pasteCmd
call setreg(a:regName, l:regContent, l:regType)
catch /^Vim\%((\a\+)\)\=:E/
- echohl ErrorMsg
" v:exception contains what is normally in v:errmsg, but with extra
" exception source info prepended, which we cut away.
let v:errmsg = substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', '')
+ echohl ErrorMsg
echomsg v:errmsg
echohl None
endtry
endfunction
-nnoremap <silent> glP :<C-u>call <SID>Paste(v:register, 'l', 'P')<CR>
-nnoremap <silent> glp :<C-u>call <SID>Paste(v:register, 'l', 'p')<CR>
-nnoremap <silent> gcP :<C-u>call <SID>Paste(v:register, 'c', 'P')<CR>
-nnoremap <silent> gcp :<C-u>call <SID>Paste(v:register, 'c', 'p')<CR>
+function! s:CreateMappings()
+ for [l:pasteName, pasteType] in [['Char', 'c'], ['Line', 'l'], ['Block', 'b']]
+ for [l:direction, l:pasteCmd] in [['After', 'p'], ['Before', 'P']]
+ let l:plugMappingName = '<Plug>UnconditionalPaste' . l:pasteName . l:direction
+ execute printf('nnoremap %s :<C-u>call <SID>Paste(v:register, %s, %s)<CR>',
+ \ l:plugMappingName,
+ \ string(l:pasteType),
+ \ string(l:pasteCmd)
+ \)
+ if ! hasmapto(l:plugMappingName, 'n')
+ execute printf('nmap <silent> g%s%s %s',
+ \ l:pasteType,
+ \ l:pasteCmd,
+ \ l:plugMappingName
+ \)
+ endif
+ endfor
+ endfor
+endfunction
+call s:CreateMappings()
+delfunction s:CreateMappings
+let &cpo = s:save_cpo
+unlet s:save_cpo
" vim: set sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
Please sign in to comment.
Something went wrong with that request. Please try again.