Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: vim-scripts/UnconditionalPaste
base: 46ba4bcf3a
...
head fork: vim-scripts/UnconditionalPaste
compare: 55e6b05aeb
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 25, 2012
Ingo Karkat Version 1.22
- BUG: When repeat.vim is not installed, the mappings do nothing. Need to :execute the :silent! call of repeat.vim to avoid that the remainder of the command line is aborted together with the call.
- Using separate autoload script to help speed up Vim startup.
3181826
Ingo Karkat Version 2.00
- ENH: Add g,p / gqp / gQp mappings to paste lines flattened with comma, queried, or recalled last used delimiter.
- ENH: Add gup / gUp mappings to paste unjoined register with queried or recalled last used delimiter pattern.
- ENH: Add CTRL-R CTRL-C mapping to insert register contents characterwise (flattened) from insert mode, and similar insert mode mappings for the other new mappings.
- CHG: Flatten all whitespace and newlines before, after, and around lines when pasting characterwise or joined.
cc5f809
Ingo Karkat Version 2.10
- ENH: Add gpp / gpP mappings to paste with one number (which depending on the current cursor position) incremented / decremented.
- FIX: For characterwise pastes with a [count], the multiplied pastes must be joined with the desired separator, not just plainly concatenated.
- FIX: Don't lose the original [count] given when repeating the mapping.
- FIX: Do not re-query on repeat of the mapping.
55e6b05
View
83 README
@@ -4,17 +4,82 @@ DESCRIPTION
If you're like me, you occasionally do a linewise yank, and then want to
insert that yanked text in the middle of some other line (or vice versa).
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, both from normal and
+insert mode.
+
+Often, the register contents aren't quite in the form you need them. Maybe you
+need to convert yanked lines to comma-separated arguments, maybe join the
+lines with another separator, maybe the reverse: un-joining a single line on
+some pattern to yield multiple lines. Though you can do the manipulation after
+pasting, this plugin offers shortcut mappings for these actions, which are
+especially helpful when you need to repeat the paste multiple times.
SOURCE
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
+
+RELATED WORKS
+- whitespaste.vim (vimscript #4351) automatically removes blank lines around
+ linewise contents, and condenses inner lines to a single one. By default, it
+ remaps p / P, but this can be changed.
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, ["x]gcP Paste characterwise (newline characters and indent are
+ flattened to spaces) [count] times.
+
+["x]glp, ["x]glP Paste linewise (even if yanked text is not a complete
+ line) [count] times.
+
+["x]gbp, ["x]gbP Paste blockwise (inserting multiple lines in-place,
+ pushing existing text further to the right) [count]
+ times.
+
+["x]g,p, ["x]g,P Paste characterwise, with each line delimited by ", "
+ instead of the newline (and indent).
+
+["x]gqp, ["x]gqP Query for a separator string, then paste
+ characterwise, with each line delimited by it.
+
+["x]gQp, ["x]gQP Paste characterwise, with each line delimited by the
+ previously queried (gqp) separator string.
+
+["x]gup, ["x]guP Query for a separator pattern, un-join the register
+ contents, then paste linewise.
+
+["x]gUp, ["x]gUP Un-join the register contents on the previously
+ queried (gup) separator pattern, then paste
+ linewise.
+
+["x]gpp, ["x]gpP Paste with the first number found on or after the
+ current cursor column (or the overall first number, if
+ no such match, or the last number, if the cursor is at
+ the end of the line) incremented / decremented by 1.
+ Do this [count] times, with each paste further
+ incremented / decremented.
+
+CTRL-R CTRL-C {0-9a-z"%#*+/:.-}
+ Insert the contents of a register characterwise
+ (newline characters and indent are flattened to
+ spaces).
+ If you have options like 'textwidth', 'formatoptions',
+ or 'autoindent' set, this will influence what will be
+ inserted.
+CTRL-R , {0-9a-z"%#*+/:.-}
+ Insert the contents of a register characterwise, with
+ each line delimited by ", " instead of the newline
+ (and indent).
+CTRL-R CTRL-Q {0-9a-z"%#*+/:.-}
+ Query for a separator string, then insert the contents
+ of a register characterwise, with each line delimited
+ by it.
+CTRL-R CTRL-Q CTRL-Q {0-9a-z"%#*+/:.-}
+ Insert the contents of a register characterwise, with
+ each line delimited by the previously queried (gqp,
+ i_CTRL-R_CTRL-Q) separator string.
+CTRL-R CTRL-U {0-9a-z"%#*+/:.-}
+ Query for a separator pattern, un-join the contents of
+ a register, then insert it linewise.
+CTRL-R CTRL-U CTRL-U {0-9a-z"%#*+/:.-}
+ Un-join the contents of
+ a register on the previously queried (gup,
+ i_CTRL_R_CTRL-U) pattern, then insert it linewise.
View
287 autoload/UnconditionalPaste.vim
@@ -0,0 +1,287 @@
+" UnconditionalPaste.vim: Force character-/line-/block-wise paste, regardless of
+" how it was yanked.
+"
+" DEPENDENCIES:
+
+" Copyright: (C) 2006-2012 Ingo Karkat
+" The VIM LICENSE applies to this script; see ':help copyright'.
+"
+" Maintainer: Ingo Karkat <ingo@karkat.de>
+" Source: Based on vimtip #1199 by cory,
+" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
+"
+" REVISION DATE REMARKS
+" 2.10.019 21-Dec-2012 FIX: For characterwise pastes with a [count],
+" the multiplied pastes must be joined with the
+" desired separator, not just plainly
+" concatenated.
+" ENH: Add mappings to paste with one number
+" (which depending on the current cursor position)
+" incremented / decremented.
+" Handle repeat of gpp with the last used offset
+" and the same number position by introducing a
+" special ".p" paste type.
+" FIX: Don't lose the original [count] given when
+" repeating the mapping. As
+" UnconditionalPaste#Paste() executes a normal
+" mode command, we need to store v:count and make
+" it available to the <Plug>-mapping via the new
+" UnconditionalPaste#GetCount() getter.
+" 2.00.018 07-Dec-2012 FIX: Differentiate between pasteType and a:how
+" argument, as setregtype() only understands the
+" former.
+" 2.00.017 06-Dec-2012 CHG: Flatten all whitespace and newlines before,
+" after, and around lines when pasting
+" characterwise or joined.
+" 2.00.016 05-Dec-2012 ENH: Add mappings to insert register contents
+" characterwise (flattened) from insert mode.
+" ENH: Add mappings to paste lines flattened with
+" comma, queried, or recalled last used delimiter.
+" ENH: Add mappings to paste unjoined register
+" with queried or recalled last used delimiter
+" pattern.
+" 1.22.015 04-Dec-2012 Split off functions into autoload script.
+" 1.22.014 28-Nov-2012 BUG: When repeat.vim is not installed, the
+" mappings do nothing. Need to :execute the
+" :silent! call of repeat.vim to avoid that the
+" remainder of the command line is aborted
+" together with the call.
+" 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
+" together with the expression register "=.
+" BUG: Move <silent> maparg to <Plug> mapping to
+" silence command repeat.
+" 1.11.010 06-Jun-2011 ENH: Support repetition of mappings through
+" repeat.vim.
+" 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
+" the paste.
+" Now supporting [count], like the built-in paste
+" command.
+" 006 08-Oct-2008 Now removing newline characters at the end of
+" the text.
+" Now, the register type is not modified by an
+" unconditional paste command.
+" Now, multiple sequential newlines are converted
+" to a single space.
+" Refactored s:FlattenRegister() to s:Flatten().
+" 005 16-Jun-2008 Using :normal with <bang>.
+" 004 30-May-2007 Added <silent> to the mapping to avoid echoing
+" of the function invocation.
+" 0.03 13-May-2006 Changed mappings from <leader>.. to g.., as
+" this is easier to type (and 'g' often introduces
+" alternative actions (like 'j' and 'gj')).
+" 0.02 10-Apr-2006 Added flattening (replacing newlines with
+" spaces) for characterwise paste.
+" 0.01 10-Apr-2006 file creation from vimtip #1199
+
+function! UnconditionalPaste#HandleExprReg( exprResult )
+ let s:exprResult = a:exprResult
+endfunction
+
+function! s:Flatten( text, separator )
+ " Remove newlines and whitespace at the begin and end of the text, convert
+ " all other newlines (plus leading and trailing whitespace) to the passed
+ " separator.
+ return substitute(substitute(a:text, '^\s*\%(\n\s*\)*\|\s*\%(\n\s*\)*$', '', 'g'), '\s*\%(\n\s*\)\+', a:separator, 'g')
+endfunction
+function! s:StripTrailingWhitespace( text )
+ return substitute(a:text, '\s\+\ze\(\n\|$\)', '', 'g')
+endfunction
+function! s:Unjoin( text, separatorPattern )
+ let l:text = substitute(a:text, a:separatorPattern, '\n', 'g')
+
+ " A (single!) trailing separator is automatically swallowed by the linewise
+ " pasting. For consistency, do the same for a single leading separator.
+ return (l:text =~# '^\n' ? l:text[1:] : l:text)
+endfunction
+function! s:Increment( text, vcol, offset )
+ let l:replacement = '\=submatch(0) + ' . a:offset
+
+ if a:vcol == -1 || a:vcol == 0 && col('.') + 1 == col('$')
+ return [-1, substitute(a:text, '\d\+\ze\D*$', l:replacement, '')]
+ endif
+
+ let l:text = a:text
+ let l:vcol = (a:vcol == 0 ? virtcol('.') : a:vcol)
+ if l:vcol > 1
+ let l:text = substitute(a:text, '\d*\%>' . (l:vcol - 1) . 'v\d\+', l:replacement, '')
+ endif
+ if l:text ==# a:text
+ return [1, substitute(a:text, '\d\+', l:replacement, '')]
+ else
+ return [l:vcol, l:text]
+ endif
+endfunction
+
+function! UnconditionalPaste#GetCount()
+ return s:count
+endfunction
+function! UnconditionalPaste#Paste( regName, how, ... )
+ let l:count = v:count
+ let s:count = v:count
+ let l:regType = getregtype(a:regName)
+ let l:regContent = getreg(a:regName, 1) " Expression evaluation inside function context may cause errors, therefore get unevaluated expression when a:regName ==# '='.
+
+ if a:regName ==# '='
+ " Cannot evaluate the expression register within a function; unscoped
+ " variables do not refer to the global scope. Therefore, evaluation
+ " happened earlier in the mappings, and stored this in s:exprResult.
+ " To get the expression result into the buffer, use the unnamed
+ " register, and restore it later.
+ let l:regName = '"'
+ let l:regContent = s:exprResult
+
+ let l:save_clipboard = &clipboard
+ set clipboard= " Avoid clobbering the selection and clipboard registers.
+ let l:save_reg = getreg(l:regName)
+ let l:save_regmode = getregtype(l:regName)
+ else
+ let l:regName = a:regName
+ endif
+
+ try
+ let l:pasteContent = l:regContent
+ let l:pasteType = 'l'
+
+ if a:how ==# 'b'
+ let l:pasteType = 'b'
+ elseif a:how =~# '^[c,qQ]$'
+ let l:pasteType = 'c'
+
+ if l:regType[0] ==# "\<C-v>"
+ let l:pasteContent = s:StripTrailingWhitespace(l:regContent)
+ else
+ let l:pasteContent = l:regContent
+ endif
+
+ if a:how ==# 'c'
+ let l:separator = ' '
+ elseif a:how ==# ','
+ let l:separator = ', '
+ elseif a:how ==# 'q'
+ let l:separator = input('Enter separator string: ')
+ if empty(l:separator)
+ execute "normal! \<C-\>\<C-n>\<Esc>" | " Beep.
+ return ''
+ endif
+ let g:UnconditionalPaste_JoinSeparator = l:separator
+ elseif a:how ==# 'Q'
+ let l:separator = g:UnconditionalPaste_JoinSeparator
+ else
+ throw 'ASSERT: Invalid how: ' . string(a:how)
+ endif
+
+ if l:count > 1
+ " To join the multiplied pastes with the desired separator, we
+ " need to process the multiplication on our own.
+ let l:pasteContent = repeat(l:pasteContent . "\n", l:count)
+ let l:count = 0
+ endif
+
+ let l:pasteContent = s:Flatten(l:pasteContent, l:separator)
+ elseif a:how ==? 'u'
+ if a:how ==# 'u'
+ let l:separatorPattern = input('Enter separator pattern: ')
+ if empty(l:separatorPattern)
+ execute "normal! \<C-\>\<C-n>\<Esc>" | " Beep.
+ return ''
+ endif
+ let g:UnconditionalPaste_UnjoinSeparatorPattern = l:separatorPattern
+ endif
+
+ let l:pasteContent = s:Unjoin(l:pasteContent, g:UnconditionalPaste_UnjoinSeparatorPattern)
+ if l:pasteContent ==# l:regContent
+ " No unjoining took place; this is probably not what the user
+ " intended (maybe wrong register?), so don't just insert the
+ " contents unchanged, but rather alert the user.
+ execute "normal! \<C-\>\<C-n>\<Esc>" | " Beep.
+ return ''
+ endif
+ elseif a:how ==# 'l' && l:regType[0] ==# "\<C-v>"
+ let l:pasteContent = s:StripTrailingWhitespace(l:regContent)
+ elseif a:how ==# 'p' || a:how ==# '.p'
+ let l:pasteType = l:regType " Keep the original paste type.
+ let l:offset = (a:1 ==# 'p' ? 1 : -1)
+ if a:how ==# 'p'
+ let l:baseCount = 1
+ let l:vcol = 0
+ elseif a:how ==# '.p'
+ " Continue increasing with the last used (saved) offset, and at
+ " the same number position (after the first paste, the cursor
+ " will have jumped to the beginning of the pasted text).
+ let l:baseCount = s:lastCount + 1
+ let l:vcol = s:lastVcol
+ else
+ throw 'ASSERT: Invalid how: ' . string(a:how)
+ endif
+ let s:lastCount = l:baseCount
+
+ let [s:lastVcol, l:pasteContent] = s:Increment(l:regContent, l:vcol, l:offset * l:baseCount)
+ if l:pasteContent ==# l:regContent
+ " No number was found in the register; this is probably not what
+ " the user intended (maybe wrong register?), so don't just
+ " insert the contents unchanged, but rather alert the user.
+ execute "normal! \<C-\>\<C-n>\<Esc>" | " Beep.
+ return ''
+ endif
+
+ if l:count > 1
+ " To increment each multiplied paste one more, we need to
+ " process the multiplication on our own.
+ let l:numbers = (l:offset > 0 ? range(l:baseCount, l:baseCount + l:count - 1) : range(-1 * (l:baseCount + l:count - 1), -1 * l:baseCount))
+ let l:pasteContent = join(map(l:numbers, 's:Increment(l:regContent, l:vcol, v:val)[1]'), (l:regType[0] ==# "\<C-v>" ? "\n" : ''))
+ let s:lastCount = l:baseCount + l:count - 1
+ let l:count = 0
+ endif
+ endif
+
+ if a:0
+ call setreg(l:regName, l:pasteContent, l:pasteType)
+ execute 'normal! "' . l:regName . (l:count ? l:count : '') . a:1
+ call setreg(l:regName, l:regContent, l:regType)
+ else
+ return l:pasteContent
+ endif
+ catch /^Vim\%((\a\+)\)\=:E/
+ " 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
+ finally
+ if a:regName ==# '='
+ call setreg('"', l:save_reg, l:save_regmode)
+ let &clipboard = l:save_clipboard
+ endif
+ endtry
+endfunction
+function! UnconditionalPaste#Insert( regName, how )
+ if a:regName !~? '[0-9a-z"%#*+:.-]'
+ " Note the lack of "="; we don't support the expression register here,
+ " because we would need to do the querying and evaluation all by
+ " ourselves.
+ execute "normal! \<C-\>\<C-n>\<Esc>" | " Beep.
+ return ''
+ endif
+
+ return UnconditionalPaste#Paste(a:regName, a:how)
+endfunction
+
+" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
View
196 doc/UnconditionalPaste.txt
@@ -1,4 +1,4 @@
-*UnconditionalPaste.txt* Force character-/line-/block-wise paste, regardless of how it was yanked.
+*UnconditionalPaste.txt* Force character-/line-/block-wise paste, regardless of how it was yanked.
UNCONDITIONAL PASTE by Ingo Karkat
*UnconditionalPaste.vim*
@@ -17,53 +17,156 @@ DESCRIPTION *UnconditionalPaste-description*
If you're like me, you occasionally do a linewise yank, and then want to
insert that yanked text in the middle of some other line (or vice versa).
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, both from normal and
+insert mode.
+
+Often, the register contents aren't quite in the form you need them. Maybe you
+need to convert yanked lines to comma-separated arguments, maybe join the
+lines with another separator, maybe the reverse: un-joining a single line on
+some pattern to yield multiple lines. Though you can do the manipulation after
+pasting, this plugin offers shortcut mappings for these actions, which are
+especially helpful when you need to repeat the paste multiple times.
SOURCE *
-Based on vimtip #1199 by cory,
+Based on vimtip #1199 by cory,
http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
+RELATED WORKS *
+
+- whitespaste.vim (vimscript #4351) automatically removes blank lines around
+ linewise contents, and condenses inner lines to a single one. By default, it
+ remaps p / P, but this can be changed.
+
==============================================================================
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.
-
+ *gcp* *gcP*
+["x]gcp, ["x]gcP Paste characterwise (newline characters and indent are
+ flattened to spaces) [count] times.
+ *glp* *glP*
+["x]glp, ["x]glP Paste linewise (even if yanked text is not a complete
+ line) [count] times.
+ *gbp* *gbP*
+["x]gbp, ["x]gbP Paste blockwise (inserting multiple lines in-place,
+ pushing existing text further to the right) [count]
+ times.
+
+ *g,p* *g,P*
+["x]g,p, ["x]g,P Paste characterwise, with each line delimited by ", "
+ instead of the newline (and indent).
+ *gqp* *gqP*
+["x]gqp, ["x]gqP Query for a separator string, then paste
+ characterwise, with each line delimited by it.
+ *gQp* *gQP*
+["x]gQp, ["x]gQP Paste characterwise, with each line delimited by the
+ previously queried (|gqp|) separator string.
+
+ *gup* *guP*
+["x]gup, ["x]guP Query for a separator pattern, un-join the register
+ contents, then paste linewise.
+ *gUp* *gUP*
+["x]gUp, ["x]gUP Un-join the register contents on the previously
+ queried (|gup|) separator pattern, then paste
+ linewise.
+
+ *gpp* *gpP*
+["x]gpp, ["x]gpP Paste with the first number found on or after the
+ current cursor column (or the overall first number, if
+ no such match, or the last number, if the cursor is at
+ the end of the line) incremented / decremented by 1.
+ Do this [count] times, with each paste further
+ incremented / decremented.
+
+
+CTRL-R CTRL-C {0-9a-z"%#*+/:.-} *i_CTRL-R_CTRL-C*
+ Insert the contents of a register characterwise
+ (newline characters and indent are flattened to
+ spaces).
+ If you have options like 'textwidth', 'formatoptions',
+ or 'autoindent' set, this will influence what will be
+ inserted.
+CTRL-R , {0-9a-z"%#*+/:.-} *i_CTRL-R_,*
+ Insert the contents of a register characterwise, with
+ each line delimited by ", " instead of the newline
+ (and indent).
+CTRL-R CTRL-Q {0-9a-z"%#*+/:.-} *i_CTRL-R_CTRL-Q*
+ Query for a separator string, then insert the contents
+ of a register characterwise, with each line delimited
+ by it.
+CTRL-R CTRL-Q CTRL-Q {0-9a-z"%#*+/:.-} *i_CTRL-R_CTRL-Q_CTRL-Q*
+ Insert the contents of a register characterwise, with
+ each line delimited by the previously queried (|gqp|,
+ |i_CTRL-R_CTRL-Q|) separator string.
+CTRL-R CTRL-U {0-9a-z"%#*+/:.-} *i_CTRL-R_CTRL-U*
+ Query for a separator pattern, un-join the contents of
+ a register, then insert it linewise.
+CTRL-R CTRL-U CTRL-U {0-9a-z"%#*+/:.-} *i_CTRL-R_CTRL-U_CTRL-U*
+ Un-join the contents of
+ a register on the previously queried (|gup|,
+ |i_CTRL_R_CTRL-U|) pattern, then insert it linewise.
==============================================================================
INSTALLATION *UnconditionalPaste-installation*
This script is packaged as a |vimball|. If you have the "gunzip" decompressor
-in your PATH, simply edit the *.vba.gz package in Vim; otherwise, decompress
+in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the |:UseVimball| command. >
- vim UnconditionalPaste.vba.gz
+ vim UnconditionalPaste*.vmb.gz
:so %
-To uninstall, use the |:RmVimball| command.
+To uninstall, use the |:RmVimball| command.
DEPENDENCIES *UnconditionalPaste-dependencies*
-- Requires Vim 7.0 or higher.
-- repeat.vim (vimscript #2136) plugin (optional).
+- Requires Vim 7.0 or higher.
+- repeat.vim (vimscript #2136) plugin (optional)
==============================================================================
CONFIGURATION *UnconditionalPaste-configuration*
+For a permanent configuration, put the following commands into your |vimrc|:
+ *g:UnconditionalPaste_JoinSeparator*
+The default separator string for the |gQp| and |i_CTRL-R_CTRL-Q_CTRL-Q|
+mappings is a <Tab> character; to preset another one (it will be overridden by
+|gqp| and |i_CTRL-R_CTRL-Q|), use: >
+ let g:UnconditionalPaste_JoinSeparator = 'text'
+<
+ *g:UnconditionalPaste_UnjoinSeparatorPattern*
+The default separator pattern for the |gUp| and |i_CTRL-R_CTRL-U_CTRL-U|
+mappings matches any whitespace and newlines (i.e. it will get rid of empty
+lines); to preset another one (it will be overridden by |gup| and
+|i_CTRL-R_CTRL-U|), use: >
+ let g:UnconditionalPaste_UnjoinSeparatorPattern = '-'
+<
+ *UnconditionalPaste-remap*
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
+ nmap <Leader>Pc <Plug>UnconditionalPasteCharBefore
+ nmap <Leader>pc <Plug>UnconditionalPasteCharAfter
+ nmap <Leader>Pl <Plug>UnconditionalPasteLineBefore
+ nmap <Leader>pl <Plug>UnconditionalPasteLineAfter
+ nmap <Leader>Pb <Plug>UnconditionalPasteBlockBefore
+ nmap <Leader>pb <Plug>UnconditionalPasteBlockAfter
+ nmap <Leader>P, <Plug>UnconditionalPasteCommaBefore
+ nmap <Leader>p, <Plug>UnconditionalPasteCommaAfter
+ nmap <Leader>Pq <Plug>UnconditionalPasteQueriedBefore
+ nmap <Leader>pq <Plug>UnconditionalPasteQueriedAfter
+ nmap <Leader>PQ <Plug>UnconditionalPasteRecallQueriedBefore
+ nmap <Leader>pQ <Plug>UnconditionalPasteRecallQueriedAfter
+ nmap <Leader>Pu <Plug>UnconditionalPasteUnjoinBefore
+ nmap <Leader>pu <Plug>UnconditionalPasteUnjoinAfter
+ nmap <Leader>PU <Plug>UnconditionalPasteRecallUnjoinBefore
+ nmap <Leader>pU <Plug>UnconditionalPasteRecallUnjoinAfter
+ nmap <Leader>Pp <Plug>UnconditionalPastePlusBefore
+ nmap <Leader>pp <Plug>UnconditionalPastePlusAfter
+
+ imap <C-G>c <Plug>UnconditionalPasteChar
+ imap <C-G>, <Plug>UnconditionalPasteComma
+ imap <C-G>q <Plug>UnconditionalPasteQueried
+ imap <C-G>Q <Plug>UnconditionalPasteRecallQueried
+ imap <C-G>u <Plug>UnconditionalPasteUnjoin
+ imap <C-G>U <Plug>UnconditionalPasteRecallUnjoin
<
==============================================================================
LIMITATIONS *UnconditionalPaste-limitations*
@@ -77,12 +180,37 @@ IDEAS *UnconditionalPaste-ideas*
==============================================================================
HISTORY *UnconditionalPaste-history*
+2.10 22-Dec-2012
+- ENH: Add gpp / gpP mappings to paste with one number (which depending on the
+ current cursor position) incremented / decremented.
+- FIX: For characterwise pastes with a [count], the multiplied pastes must be
+ joined with the desired separator, not just plainly concatenated.
+- FIX: Don't lose the original [count] given when repeating the mapping.
+- FIX: Do not re-query on repeat of the mapping.
+
+2.00 05-Dec-2012
+- ENH: Add g,p / gqp / gQp mappings to paste lines flattened with comma,
+ queried, or recalled last used delimiter.
+- ENH: Add gup / gUp mappings to paste unjoined register with queried or
+ recalled last used delimiter pattern.
+- ENH: Add CTRL-R CTRL-C mapping to insert register contents characterwise
+ (flattened) from insert mode, and similar insert mode mappings for the other
+ new mappings.
+- CHG: Flatten all whitespace and newlines before, after, and around lines
+ when pasting characterwise or joined.
+
+1.22 04-Dec-2012
+- BUG: When repeat.vim is not installed, the mappings do nothing. Need to
+ :execute the :silent! call of repeat.vim to avoid that the remainder of the
+ command line is aborted together with the call.
+- Using separate autoload script to help speed up Vim startup.
+
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.
+ text and pasting as new lines.
- ENH: When pasting a blockwise register as characters, flatten and shrink all
- trailing whitespace to a single space.
+ trailing whitespace to a single space.
1.20 30-Sep-2011
BUG: Repeat always used the unnamed register. Add register registration to
@@ -92,23 +220,23 @@ repeat.vim version 1.0 (that hopefully makes it into upstream), which is
available at https://github.com/inkarkat/vim-repeat/zipball/1.0ENH1
1.11 06-Jun-2011
-ENH: Support repetition of mappings through repeat.vim.
+ENH: Support repetition of mappings through repeat.vim.
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.
+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.
+Published, prompted by a related question on reddit.
0.01 10-Apr-2006
-Started development, based on vimtip #1199 by cory.
+Started development, based on vimtip #1199 by cory.
==============================================================================
-Copyright: (C) 2006-2011 Ingo Karkat
-The VIM LICENSE applies to this script; see |copyright|.
+Copyright: (C) 2006-2012 Ingo Karkat
+The VIM LICENSE applies to this script; see |copyright|.
Maintainer: Ingo Karkat <ingo@karkat.de>
==============================================================================
View
221 plugin/UnconditionalPaste.vim
@@ -1,63 +1,92 @@
" UnconditionalPaste.vim: Force character-/line-/block-wise paste, regardless of
-" how it was yanked.
+" how it was yanked.
"
" DEPENDENCIES:
-" - Requires Vim 7.0 or higher.
-" - repeat.vim (vimscript #2136) autoload script (optional).
+" - Requires Vim 7.0 or higher.
+" - UnconditionalPaste.vim autoload script
+" - repeat.vim (vimscript #2136) autoload script (optional)
-" Copyright: (C) 2006-2011 Ingo Karkat
-" The VIM LICENSE applies to this script; see ':help copyright'.
+" Copyright: (C) 2006-2012 Ingo Karkat
+" The VIM LICENSE applies to this script; see ':help copyright'.
"
" Maintainer: Ingo Karkat <ingo@karkat.de>
-" Source: Based on vimtip #1199 by cory,
+" Source: Based on vimtip #1199 by cory,
" http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
"
-" REVISION DATE REMARKS
+" REVISION DATE REMARKS
+" 2.10.018 22-Dec-2012 FIX: Do not re-query on repeat of the mapping.
+" This wasn't updated for the Query mapping and
+" not implemented at all for the Unjoin mapping.
+" 2.10.017 21-Dec-2012 ENH: Add mappings to paste with one number
+" (which depending on the current cursor position)
+" incremented / decremented.
+" Handle repeat of gpp with the last used offset
+" and the same number position by introducing a
+" special ".p" paste type.
+" FIX: Don't lose the original [count] given when
+" repeating the mapping. As
+" UnconditionalPaste#Paste() executes a normal
+" mode command, we need to store v:count and make
+" it available to the <Plug>-mapping via the new
+" UnconditionalPaste#GetCount() getter.
+" 2.00.016 05-Dec-2012 ENH: Add mappings to insert register contents
+" characterwise (flattened) from insert mode.
+" ENH: Add mappings to paste lines flattened with
+" comma, queried, or recalled last used delimiter.
+" ENH: Add mappings to paste unjoined register
+" with queried or recalled last used delimiter
+" pattern.
+" 1.22.015 04-Dec-2012 Split off functions into autoload script.
+" 1.22.014 28-Nov-2012 BUG: When repeat.vim is not installed, the
+" mappings do nothing. Need to :execute the
+" :silent! call of repeat.vim to avoid that the
+" remainder of the command line is aborted
+" together with the call.
" 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.
+" 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.
+" 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
-" together with the expression register "=.
+" together with the expression register "=.
" BUG: Move <silent> maparg to <Plug> mapping to
-" silence command repeat.
+" silence command repeat.
" 1.11.010 06-Jun-2011 ENH: Support repetition of mappings through
-" repeat.vim.
+" repeat.vim.
" 1.10.009 12-Jan-2011 Incorporated suggestions by Peter Rincker
-" (thanks for the patch!):
+" (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.
+" <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.
+" supported Vim version.
" 007 15-May-2009 Now catching and reporting any errors caused by
-" the paste.
+" the paste.
" Now supporting [count], like the built-in paste
-" command.
+" command.
" 006 08-Oct-2008 Now removing newline characters at the end of
-" the text.
+" the text.
" Now, the register type is not modified by an
-" unconditional paste command.
+" unconditional paste command.
" Now, multiple sequential newlines are converted
-" to a single space.
-" Refactored s:FlattenRegister() to s:Flatten().
-" 005 16-Jun-2008 Using :normal with <bang>.
+" to a single space.
+" Refactored s:FlattenRegister() to s:Flatten().
+" 005 16-Jun-2008 Using :normal with <bang>.
" 004 30-May-2007 Added <silent> to the mapping to avoid echoing
-" of the function invocation.
+" of the function invocation.
" 0.03 13-May-2006 Changed mappings from <leader>.. to g.., as
" this is easier to type (and 'g' often introduces
-" alternative actions (like 'j' and 'gj')).
+" alternative actions (like 'j' and 'gj')).
" 0.02 10-Apr-2006 Added flattening (replacing newlines with
-" spaces) for characterwise paste.
+" spaces) for characterwise paste.
" 0.01 10-Apr-2006 file creation from vimtip #1199
-" Avoid installing twice or when in unsupported Vim version.
+" Avoid installing twice or when in unsupported Vim version.
if exists('g:loaded_UnconditionalPaste') || (v:version < 700)
finish
endif
@@ -66,90 +95,57 @@ let g:loaded_UnconditionalPaste = 1
let s:save_cpo = &cpo
set cpo&vim
-function! s:HandleExprReg( exprResult )
- let s:exprResult = a:exprResult
-endfunction
+"- configuration ---------------------------------------------------------------
-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:StripTrailingWhitespace( text )
- return substitute(a:text, '\s\+\ze\(\n\|$\)', '', 'g')
-endfunction
-
-function! s:Paste( regName, pasteType, pasteCmd )
- let l:regType = getregtype(a:regName)
- let l:regContent = getreg(a:regName, 1) " Expression evaluation inside function context may cause errors, therefore get unevaluated expression when a:regName ==# '='.
+if ! exists('g:UnconditionalPaste_JoinSeparator')
+ let g:UnconditionalPaste_JoinSeparator = "\t"
+endif
+if ! exists('g:UnconditionalPaste_UnjoinSeparatorPattern')
+ let g:UnconditionalPaste_UnjoinSeparatorPattern = '\_s\+'
+endif
- if a:regName ==# '='
- " Cannot evaluate the expression register within a function; unscoped
- " variables do not refer to the global scope. Therefore, evaluation
- " happened earlier in the mappings, and stored this in s:exprResult.
- " To get the expression result into the buffer, use the unnamed
- " register, and restore it later.
- let l:regName = '"'
- let l:regContent = s:exprResult
- let l:save_clipboard = &clipboard
- set clipboard= " Avoid clobbering the selection and clipboard registers.
- let l:save_reg = getreg(l:regName)
- let l:save_regmode = getregtype(l:regName)
- else
- let l:regName = a:regName
- endif
- try
- 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/
- " 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
- finally
- if a:regName ==# '='
- call setreg('"', l:save_reg, l:save_regmode)
- let &clipboard = l:save_clipboard
- endif
- endtry
-endfunction
+"- mappings --------------------------------------------------------------------
function! s:CreateMappings()
- for [l:pasteName, pasteType] in [['Char', 'c'], ['Line', 'l'], ['Block', 'b']]
+ for [l:pasteName, pasteType] in
+ \ [
+ \ ['Char', 'c'], ['Line', 'l'], ['Block', 'b'], ['Comma', ','],
+ \ ['Queried', 'q'], ['RecallQueried', 'Q'],
+ \ ['Unjoin', 'u'], ['RecallUnjoin', 'U'],
+ \ ['Plus', 'p'], ['PlusRepeat', '.p']
+ \ ]
for [l:direction, l:pasteCmd] in [['After', 'p'], ['Before', 'P']]
let l:mappingName = 'UnconditionalPaste' . l:pasteName . l:direction
let l:plugMappingName = '<Plug>' . l:mappingName
+
+ if l:pasteType ==# 'q' || l:pasteType ==# 'u'
+ " On repeat of one of the mappings that query, we want to skip
+ " the query and recall the last queried separator instead.
+ let l:mappingName = 'UnconditionalPasteRecall' . l:pasteName . l:direction
+ elseif l:pasteType ==# 'p'
+ " On repeat of the UnconditionalPastePlus mapping, we want to
+ " continue increasing with the last used (saved) offset, and at
+ " the same number position (after the first paste, the cursor
+ " will have jumped to the beginning of the pasted text).
+ let l:mappingName = 'UnconditionalPaste' . l:pasteName . 'Repeat' . l:direction
+ endif
execute printf('nnoremap <silent> %s :<C-u>' .
- \ 'silent! call repeat#setreg("\<lt>Plug>%s", v:register)<Bar>' .
- \ 'if v:register ==# "="<Bar>' .
- \ ' call <SID>HandleExprReg(getreg("="))<Bar>' .
- \ 'endif<Bar>' .
- \ 'call <SID>Paste(v:register, %s, %s)<Bar>' .
- \ 'silent! call repeat#set("\<lt>Plug>%s")<CR>',
+ \ 'execute ''silent! call repeat#setreg("\<lt>Plug>%s", v:register)''<Bar>' .
+ \ 'if v:register ==# "="<Bar>' .
+ \ ' call UnconditionalPaste#HandleExprReg(getreg("="))<Bar>' .
+ \ 'endif<Bar>' .
+ \ 'call UnconditionalPaste#Paste(v:register, %s, %s)<Bar>' .
+ \ 'silent! call repeat#set("\<lt>Plug>%s", UnconditionalPaste#GetCount())<CR>',
\
- \ l:plugMappingName,
- \ l:mappingName,
- \ string(l:pasteType),
- \ string(l:pasteCmd),
- \ l:mappingName
+ \ l:plugMappingName,
+ \ l:mappingName,
+ \ string(l:pasteType),
+ \ string(l:pasteCmd),
+ \ l:mappingName
\)
- if ! hasmapto(l:plugMappingName, 'n')
+ if ! hasmapto(l:plugMappingName, 'n') && len(l:pasteType) == 1
execute printf('nmap g%s%s %s',
\ l:pasteType,
\ l:pasteCmd,
@@ -158,6 +154,29 @@ function! s:CreateMappings()
endif
endfor
endfor
+
+ for [l:pasteName, pasteType, pasteKey] in
+ \ [
+ \ ['Char', 'c', '<C-c>'], ['Comma', ',', ','],
+ \ ['Queried', 'q', '<C-q>'], ['RecallQueried', 'Q', '<C-q><C-q>'],
+ \ ['Unjoin', 'u', '<C-u>'], ['RecallUnjoin', 'U', '<C-u><C-u>']
+ \ ]
+ let l:plugMappingName = '<Plug>UnconditionalPaste' . l:pasteName
+ " XXX: Can only use i_CTRL-R here (though I want literal insertion, not
+ " as typed); i_CTRL-R_CTRL-R with the expression register cannot insert
+ " newlines (^@ are inserted), and i_CTRL-R_CTRL-O inserts above the
+ " current line when the register ends with a newline.
+ execute printf('inoremap <silent> %s <C-r>=UnconditionalPaste#Insert(nr2char(getchar()), %s)<CR>',
+ \ l:plugMappingName,
+ \ string(l:pasteType)
+ \)
+ if ! hasmapto(l:plugMappingName, 'i')
+ execute printf('imap <C-r>%s %s',
+ \ l:pasteKey,
+ \ l:plugMappingName
+ \)
+ endif
+ endfor
endfunction
call s:CreateMappings()
delfunction s:CreateMappings

No commit comments for this range

Something went wrong with that request. Please try again.