Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 55e6b05aeb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 244 lines (207 sloc) 10.755 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
*UnconditionalPaste.txt* Force character-/line-/block-wise paste, regardless of how it was yanked.

UNCONDITIONAL PASTE by Ingo Karkat
*UnconditionalPaste.vim*
description |UnconditionalPaste-description|
usage |UnconditionalPaste-usage|
installation |UnconditionalPaste-installation|
configuration |UnconditionalPaste-configuration|
limitations |UnconditionalPaste-limitations|
known problems |UnconditionalPaste-known-problems|
todo |UnconditionalPaste-todo|
history |UnconditionalPaste-history|

==============================================================================
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, 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

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*
["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 *.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*.vmb.gz
    :so %
To uninstall, use the |:RmVimball| command.

DEPENDENCIES *UnconditionalPaste-dependencies*

- 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 <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*

KNOWN PROBLEMS *UnconditionalPaste-known-problems*

TODO *UnconditionalPaste-todo*

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.
- 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
with the expression register "=. Requires a so far inofficial update to
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.

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.

0.01 10-Apr-2006
Started development, based on vimtip #1199 by cory.

==============================================================================
Copyright: (C) 2006-2012 Ingo Karkat
The VIM LICENSE applies to this script; see |copyright|.

Maintainer: Ingo Karkat <ingo@karkat.de>
==============================================================================
 vim:tw=78:ts=8:ft=help:norl:
Something went wrong with that request. Please try again.