Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 4 files changed
  • 0 comments
  • 1 contributor
Dec 25, 2012
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
83  README
@@ -4,17 +4,82 @@ DESCRIPTION
4 4
 If you're like me, you occasionally do a linewise yank, and then want to
5 5
 insert that yanked text in the middle of some other line (or vice versa).
6 6
 The mappings defined by this plugin will allow you to do a character-, line-,
7  
-or block-wise paste no matter how you yanked the text.
  7
+or block-wise paste no matter how you yanked the text, both from normal and
  8
+insert mode.
  9
+
  10
+Often, the register contents aren't quite in the form you need them. Maybe you
  11
+need to convert yanked lines to comma-separated arguments, maybe join the
  12
+lines with another separator, maybe the reverse: un-joining a single line on
  13
+some pattern to yield multiple lines. Though you can do the manipulation after
  14
+pasting, this plugin offers shortcut mappings for these actions, which are
  15
+especially helpful when you need to repeat the paste multiple times.
8 16
 
9 17
 SOURCE
10 18
 Based on vimtip #1199 by cory,
11  
-    http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
  19
+    http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
  20
+
  21
+RELATED WORKS
  22
+- whitespaste.vim (vimscript #4351) automatically removes blank lines around
  23
+  linewise contents, and condenses inner lines to a single one. By default, it
  24
+  remaps p / P, but this can be changed.
12 25
 
13 26
 USAGE
14  
-["x]gcp                 Paste characterwise (newline characters are flattened
15  
-["x]gcP                 to spaces) [count] times.
16  
-["x]glp                 Paste linewise (even if yanked text is not a complete
17  
-["x]glP                 line) [count] times.
18  
-["x]gbp                 Paste blockwise (inserting multiple lines in-place,
19  
-["x]gbP                 pushing existing text further to the right) [count]
20  
-                        times.
  27
+["x]gcp, ["x]gcP        Paste characterwise (newline characters and indent are
  28
+                        flattened to spaces) [count] times.
  29
+
  30
+["x]glp, ["x]glP        Paste linewise (even if yanked text is not a complete
  31
+                        line) [count] times.
  32
+
  33
+["x]gbp, ["x]gbP        Paste blockwise (inserting multiple lines in-place,
  34
+                        pushing existing text further to the right) [count]
  35
+                        times.
  36
+
  37
+["x]g,p, ["x]g,P        Paste characterwise, with each line delimited by ", "
  38
+                        instead of the newline (and indent).
  39
+
  40
+["x]gqp, ["x]gqP        Query for a separator string, then paste
  41
+                        characterwise, with each line delimited by it.
  42
+
  43
+["x]gQp, ["x]gQP        Paste characterwise, with each line delimited by the
  44
+                        previously queried (gqp) separator string.
  45
+
  46
+["x]gup, ["x]guP        Query for a separator pattern, un-join the register
  47
+                        contents, then paste linewise.
  48
+
  49
+["x]gUp, ["x]gUP        Un-join the register contents on the previously
  50
+                        queried (gup) separator pattern, then paste
  51
+                        linewise.
  52
+
  53
+["x]gpp, ["x]gpP        Paste with the first number found on or after the
  54
+                        current cursor column (or the overall first number, if
  55
+                        no such match, or the last number, if the cursor is at
  56
+                        the end of the line) incremented / decremented by 1.
  57
+                        Do this [count] times, with each paste further
  58
+                        incremented / decremented.
  59
+
  60
+CTRL-R CTRL-C {0-9a-z"%#*+/:.-}
  61
+                        Insert the contents of a register characterwise
  62
+                        (newline characters and indent are flattened to
  63
+                        spaces).
  64
+                        If you have options like 'textwidth', 'formatoptions',
  65
+                        or 'autoindent' set, this will influence what will be
  66
+                        inserted.
  67
+CTRL-R , {0-9a-z"%#*+/:.-}
  68
+                        Insert the contents of a register characterwise, with
  69
+                        each line delimited by ", " instead of the newline
  70
+                        (and indent).
  71
+CTRL-R CTRL-Q {0-9a-z"%#*+/:.-}
  72
+                        Query for a separator string, then insert the contents
  73
+                        of a register characterwise, with each line delimited
  74
+                        by it.
  75
+CTRL-R CTRL-Q CTRL-Q {0-9a-z"%#*+/:.-}
  76
+                        Insert the contents of a register characterwise, with
  77
+                        each line delimited by the previously queried (gqp,
  78
+                        i_CTRL-R_CTRL-Q) separator string.
  79
+CTRL-R CTRL-U {0-9a-z"%#*+/:.-}
  80
+                        Query for a separator pattern, un-join the contents of
  81
+                        a register, then insert it linewise.
  82
+CTRL-R CTRL-U CTRL-U {0-9a-z"%#*+/:.-}
  83
+                        Un-join the contents of
  84
+                        a register on the previously queried (gup,
  85
+                        i_CTRL_R_CTRL-U) pattern, then insert it linewise.
128  autoload/UnconditionalPaste.vim
... ...
@@ -0,0 +1,128 @@
  1
+" UnconditionalPaste.vim: Force character-/line-/block-wise paste, regardless of
  2
+" how it was yanked.
  3
+"
  4
+" DEPENDENCIES:
  5
+
  6
+" Copyright: (C) 2006-2012 Ingo Karkat
  7
+"   The VIM LICENSE applies to this script; see ':help copyright'.
  8
+"
  9
+" Maintainer:	Ingo Karkat <ingo@karkat.de>
  10
+" Source: Based on vimtip #1199 by cory,
  11
+"	  http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
  12
+"
  13
+" REVISION	DATE		REMARKS
  14
+"   1.22.015	04-Dec-2012	Split off functions into autoload script.
  15
+"   1.22.014	28-Nov-2012	BUG: When repeat.vim is not installed, the
  16
+"				mappings do nothing. Need to :execute the
  17
+"				:silent! call of repeat.vim to avoid that the
  18
+"				remainder of the command line is aborted
  19
+"				together with the call.
  20
+"   1.21.013	02-Dec-2011	ENH: When pasting a blockwise register as lines,
  21
+"				strip all trailing whitespace. This is useful
  22
+"				when cutting a block of text from a column-like
  23
+"				text and pasting as new lines.
  24
+"				ENH: When pasting a blockwise register as
  25
+"				characters, flatten and shrink all trailing
  26
+"				whitespace to a single space.
  27
+"   1.20.012	29-Sep-2011	BUG: Repeat always used the unnamed register.
  28
+"				Add register registration to enhanced repeat.vim
  29
+"				plugin, which also handles repetition when used
  30
+"				together with the expression register "=.
  31
+"				BUG: Move <silent> maparg to <Plug> mapping to
  32
+"				silence command repeat.
  33
+"   1.11.010	06-Jun-2011	ENH: Support repetition of mappings through
  34
+"				repeat.vim.
  35
+"   1.10.009	12-Jan-2011	Incorporated suggestions by Peter Rincker
  36
+"				(thanks for the patch!):
  37
+"				Made mappings configurable via the customary
  38
+"				<Plug> mappings.
  39
+"				Added mappings gbp, gbP for blockwise pasting.
  40
+"				Now requires Vim version 7.0 or higher.
  41
+"   1.00.008	10-Dec-2010	Prepared for publishing; find out lowest
  42
+"				supported Vim version.
  43
+"	007	15-May-2009	Now catching and reporting any errors caused by
  44
+"				the paste.
  45
+"				Now supporting [count], like the built-in paste
  46
+"				command.
  47
+"	006	08-Oct-2008	Now removing newline characters at the end of
  48
+"				the text.
  49
+"				Now, the register type is not modified by an
  50
+"				unconditional paste command.
  51
+"				Now, multiple sequential newlines are converted
  52
+"				to a single space.
  53
+"				Refactored s:FlattenRegister() to s:Flatten().
  54
+"	005	16-Jun-2008	Using :normal with <bang>.
  55
+"	004	30-May-2007	Added <silent> to the mapping to avoid echoing
  56
+"				of the function invocation.
  57
+"	0.03	13-May-2006	Changed mappings from <leader>.. to g.., as
  58
+"				this is easier to type (and 'g' often introduces
  59
+"				alternative actions (like 'j' and 'gj')).
  60
+"	0.02	10-Apr-2006	Added flattening (replacing newlines with
  61
+"				spaces) for characterwise paste.
  62
+"	0.01	10-Apr-2006	file creation from vimtip #1199
  63
+
  64
+function! UnconditionalPaste#HandleExprReg( exprResult )
  65
+    let s:exprResult = a:exprResult
  66
+endfunction
  67
+
  68
+function! s:Flatten( text )
  69
+    " Remove newline characters at the end of the text, convert all other
  70
+    " newlines to a single space.
  71
+    return substitute(substitute(a:text, '\n\+$', '', 'g'), '\n\+', ' ', 'g')
  72
+endfunction
  73
+function! s:StripTrailingWhitespace( text )
  74
+    return substitute(a:text, '\s\+\ze\(\n\|$\)', '', 'g')
  75
+endfunction
  76
+
  77
+function! UnconditionalPaste#Paste( regName, pasteType, pasteCmd )
  78
+    let l:regType = getregtype(a:regName)
  79
+    let l:regContent = getreg(a:regName, 1) " Expression evaluation inside function context may cause errors, therefore get unevaluated expression when a:regName ==# '='.
  80
+
  81
+    if a:regName ==# '='
  82
+	" Cannot evaluate the expression register within a function; unscoped
  83
+	" variables do not refer to the global scope. Therefore, evaluation
  84
+	" happened earlier in the mappings, and stored this in s:exprResult.
  85
+	" To get the expression result into the buffer, use the unnamed
  86
+	" register, and restore it later.
  87
+	let l:regName = '"'
  88
+	let l:regContent = s:exprResult
  89
+
  90
+	let l:save_clipboard = &clipboard
  91
+	set clipboard= " Avoid clobbering the selection and clipboard registers.
  92
+	let l:save_reg = getreg(l:regName)
  93
+	let l:save_regmode = getregtype(l:regName)
  94
+    else
  95
+	let l:regName = a:regName
  96
+    endif
  97
+
  98
+    try
  99
+	let l:pasteContent = l:regContent
  100
+	if a:pasteType ==# 'c'
  101
+	    if l:regType[0] ==# "\<C-v>"
  102
+		let l:pasteContent = s:Flatten(s:StripTrailingWhitespace(l:regContent))
  103
+	    else
  104
+		let l:pasteContent = s:Flatten(l:regContent)
  105
+	    endif
  106
+	elseif a:pasteType ==# 'l' && l:regType[0] ==# "\<C-v>"
  107
+	    let l:pasteContent = s:StripTrailingWhitespace(l:regContent)
  108
+	endif
  109
+
  110
+	call setreg(l:regName, l:pasteContent, a:pasteType)
  111
+	    execute 'normal! "' . l:regName . (v:count ? v:count : '') . a:pasteCmd
  112
+	call setreg(l:regName, l:regContent, l:regType)
  113
+    catch /^Vim\%((\a\+)\)\=:E/
  114
+	" v:exception contains what is normally in v:errmsg, but with extra
  115
+	" exception source info prepended, which we cut away.
  116
+	let v:errmsg = substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', '')
  117
+	echohl ErrorMsg
  118
+	echomsg v:errmsg
  119
+	echohl None
  120
+    finally
  121
+	if a:regName ==# '='
  122
+	    call setreg('"', l:save_reg, l:save_regmode)
  123
+	    let &clipboard = l:save_clipboard
  124
+	endif
  125
+    endtry
  126
+endfunction
  127
+
  128
+" vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :
60  doc/UnconditionalPaste.txt
... ...
@@ -1,4 +1,4 @@
1  
-*UnconditionalPaste.txt* Force character-/line-/block-wise paste, regardless of how it was yanked. 
  1
+*UnconditionalPaste.txt* Force character-/line-/block-wise paste, regardless of how it was yanked.
2 2
 
3 3
 		    UNCONDITIONAL PASTE    by Ingo Karkat
4 4
 						      *UnconditionalPaste.vim*
@@ -21,36 +21,36 @@ or block-wise paste no matter how you yanked the text.
21 21
 
22 22
 SOURCE									     *
23 23
 
24  
-Based on vimtip #1199 by cory, 
  24
+Based on vimtip #1199 by cory,
25 25
     http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
26 26
 
27 27
 ==============================================================================
28 28
 USAGE						    *UnconditionalPaste-usage*
29 29
 					   *gcp* *gcP* *glp* *glP* *gbp* *gbP*
30 30
 ["x]gcp			Paste characterwise (newline characters are flattened
31  
-["x]gcP			to spaces) [count] times. 
  31
+["x]gcP			to spaces) [count] times.
32 32
 ["x]glp			Paste linewise (even if yanked text is not a complete
33  
-["x]glP			line) [count] times. 
  33
+["x]glP			line) [count] times.
34 34
 ["x]gbp			Paste blockwise (inserting multiple lines in-place,
35 35
 ["x]gbP			pushing existing text further to the right) [count]
36  
-			times. 
  36
+			times.
37 37
 
38 38
 
39 39
 ==============================================================================
40 40
 INSTALLATION				     *UnconditionalPaste-installation*
41 41
 
42 42
 This script is packaged as a |vimball|. If you have the "gunzip" decompressor
43  
-in your PATH, simply edit the *.vba.gz package in Vim; otherwise, decompress
  43
+in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
44 44
 the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
45 45
 vimball or via the |:UseVimball| command. >
46  
-    vim UnconditionalPaste.vba.gz
  46
+    vim UnconditionalPaste*.vmb.gz
47 47
     :so %
48  
-To uninstall, use the |:RmVimball| command. 
  48
+To uninstall, use the |:RmVimball| command.
49 49
 
50 50
 DEPENDENCIES				     *UnconditionalPaste-dependencies*
51 51
 
52  
-- Requires Vim 7.0 or higher. 
53  
-- repeat.vim (vimscript #2136) plugin (optional). 
  52
+- Requires Vim 7.0 or higher.
  53
+- repeat.vim (vimscript #2136) plugin (optional)
54 54
 
55 55
 ==============================================================================
56 56
 CONFIGURATION				    *UnconditionalPaste-configuration*
@@ -58,12 +58,12 @@ CONFIGURATION				    *UnconditionalPaste-configuration*
58 58
 If you want to use different mappings (e.g. starting with <Leader>), map your
59 59
 keys to the <Plug>UnconditionalPaste... mapping targets _before_ sourcing this
60 60
 script (e.g. in your |vimrc|): >
61  
-    nmap <silent> <Leader>Pc <Plug>UnconditionalPasteCharBefore
62  
-    nmap <silent> <Leader>pc <Plug>UnconditionalPasteCharAfter
63  
-    nmap <silent> <Leader>Pl <Plug>UnconditionalPasteLineBefore
64  
-    nmap <silent> <Leader>pl <Plug>UnconditionalPasteLineAfter
65  
-    nmap <silent> <Leader>Pb <Plug>UnconditionalPasteBlockBefore
66  
-    nmap <silent> <Leader>pb <Plug>UnconditionalPasteBlockAfter
  61
+    nmap <Leader>Pc <Plug>UnconditionalPasteCharBefore
  62
+    nmap <Leader>pc <Plug>UnconditionalPasteCharAfter
  63
+    nmap <Leader>Pl <Plug>UnconditionalPasteLineBefore
  64
+    nmap <Leader>pl <Plug>UnconditionalPasteLineAfter
  65
+    nmap <Leader>Pb <Plug>UnconditionalPasteBlockBefore
  66
+    nmap <Leader>pb <Plug>UnconditionalPasteBlockAfter
67 67
 <
68 68
 ==============================================================================
69 69
 LIMITATIONS				      *UnconditionalPaste-limitations*
@@ -77,12 +77,18 @@ IDEAS						    *UnconditionalPaste-ideas*
77 77
 ==============================================================================
78 78
 HISTORY						  *UnconditionalPaste-history*
79 79
 
  80
+1.22	04-Dec-2012
  81
+- BUG: When repeat.vim is not installed, the mappings do nothing. Need to
  82
+  :execute the :silent! call of repeat.vim to avoid that the remainder of the
  83
+  command line is aborted together with the call.
  84
+- Using separate autoload script to help speed up Vim startup.
  85
+
80 86
 1.21	02-Dec-2011
81 87
 - ENH: When pasting a blockwise register as lines, strip all trailing
82 88
   whitespace. This is useful when cutting a block of text from a column-like
83  
-  text and pasting as new lines.  
  89
+  text and pasting as new lines.
84 90
 - ENH: When pasting a blockwise register as characters, flatten and shrink all
85  
-  trailing whitespace to a single space. 
  91
+  trailing whitespace to a single space.
86 92
 
87 93
 1.20	30-Sep-2011
88 94
 BUG: Repeat always used the unnamed register. Add register registration to
@@ -92,23 +98,23 @@ repeat.vim version 1.0 (that hopefully makes it into upstream), which is
92 98
 available at https://github.com/inkarkat/vim-repeat/zipball/1.0ENH1
93 99
 
94 100
 1.11	06-Jun-2011
95  
-ENH: Support repetition of mappings through repeat.vim. 
  101
+ENH: Support repetition of mappings through repeat.vim.
96 102
 
97 103
 1.10	12-Jan-2011
98  
-Incorporated suggestions by Peter Rincker (thanks for the patch!): 
99  
-- Made mappings configurable via the customary <Plug> mappings. 
100  
-- Added mappings gbp, gbP for blockwise pasting. 
101  
-- Now requires Vim version 7.0 or higher. 
  104
+Incorporated suggestions by Peter Rincker (thanks for the patch!):
  105
+- Made mappings configurable via the customary <Plug> mappings.
  106
+- Added mappings gbp, gbP for blockwise pasting.
  107
+- Now requires Vim version 7.0 or higher.
102 108
 
103 109
 1.00	10-Dec-2010
104  
-Published, prompted by a related question on reddit. 
  110
+Published, prompted by a related question on reddit.
105 111
 
106 112
 0.01	10-Apr-2006
107  
-Started development, based on vimtip #1199 by cory. 
  113
+Started development, based on vimtip #1199 by cory.
108 114
 
109 115
 ==============================================================================
110  
-Copyright: (C) 2006-2011 Ingo Karkat
111  
-The VIM LICENSE applies to this script; see |copyright|. 
  116
+Copyright: (C) 2006-2012 Ingo Karkat
  117
+The VIM LICENSE applies to this script; see |copyright|.
112 118
 
113 119
 Maintainer:	Ingo Karkat <ingo@karkat.de>
114 120
 ==============================================================================
135  plugin/UnconditionalPaste.vim
... ...
@@ -1,63 +1,70 @@
1 1
 " UnconditionalPaste.vim: Force character-/line-/block-wise paste, regardless of
2  
-" how it was yanked. 
  2
+" how it was yanked.
3 3
 "
4 4
 " DEPENDENCIES:
5  
-"   - Requires Vim 7.0 or higher. 
6  
-"   - repeat.vim (vimscript #2136) autoload script (optional). 
  5
+"   - Requires Vim 7.0 or higher.
  6
+"   - UnconditionalPaste.vim autoload script
  7
+"   - repeat.vim (vimscript #2136) autoload script (optional)
7 8
 
8  
-" Copyright: (C) 2006-2011 Ingo Karkat
9  
-"   The VIM LICENSE applies to this script; see ':help copyright'. 
  9
+" Copyright: (C) 2006-2012 Ingo Karkat
  10
+"   The VIM LICENSE applies to this script; see ':help copyright'.
10 11
 "
11 12
 " Maintainer:	Ingo Karkat <ingo@karkat.de>
12  
-" Source: Based on vimtip #1199 by cory, 
  13
+" Source: Based on vimtip #1199 by cory,
13 14
 "	  http://vim.wikia.com/wiki/Unconditional_linewise_or_characterwise_paste
14 15
 "
15  
-" REVISION	DATE		REMARKS 
  16
+" REVISION	DATE		REMARKS
  17
+"   1.22.015	04-Dec-2012	Split off functions into autoload script.
  18
+"   1.22.014	28-Nov-2012	BUG: When repeat.vim is not installed, the
  19
+"				mappings do nothing. Need to :execute the
  20
+"				:silent! call of repeat.vim to avoid that the
  21
+"				remainder of the command line is aborted
  22
+"				together with the call.
16 23
 "   1.21.013	02-Dec-2011	ENH: When pasting a blockwise register as lines,
17 24
 "				strip all trailing whitespace. This is useful
18 25
 "				when cutting a block of text from a column-like
19  
-"				text and pasting as new lines.  
  26
+"				text and pasting as new lines.
20 27
 "				ENH: When pasting a blockwise register as
21 28
 "				characters, flatten and shrink all trailing
22  
-"				whitespace to a single space. 
23  
-"   1.20.012	29-Sep-2011	BUG: Repeat always used the unnamed register. 
  29
+"				whitespace to a single space.
  30
+"   1.20.012	29-Sep-2011	BUG: Repeat always used the unnamed register.
24 31
 "				Add register registration to enhanced repeat.vim
25 32
 "				plugin, which also handles repetition when used
26  
-"				together with the expression register "=. 
  33
+"				together with the expression register "=.
27 34
 "				BUG: Move <silent> maparg to <Plug> mapping to
28  
-"				silence command repeat. 
  35
+"				silence command repeat.
29 36
 "   1.11.010	06-Jun-2011	ENH: Support repetition of mappings through
30  
-"				repeat.vim. 
  37
+"				repeat.vim.
31 38
 "   1.10.009	12-Jan-2011	Incorporated suggestions by Peter Rincker
32  
-"				(thanks for the patch!): 
  39
+"				(thanks for the patch!):
33 40
 "				Made mappings configurable via the customary
34  
-"				<Plug> mappings. 
35  
-"				Added mappings gbp, gbP for blockwise pasting. 
36  
-"				Now requires Vim version 7.0 or higher. 
  41
+"				<Plug> mappings.
  42
+"				Added mappings gbp, gbP for blockwise pasting.
  43
+"				Now requires Vim version 7.0 or higher.
37 44
 "   1.00.008	10-Dec-2010	Prepared for publishing; find out lowest
38  
-"				supported Vim version. 
  45
+"				supported Vim version.
39 46
 "	007	15-May-2009	Now catching and reporting any errors caused by
40  
-"				the paste. 
  47
+"				the paste.
41 48
 "				Now supporting [count], like the built-in paste
42  
-"				command. 
  49
+"				command.
43 50
 "	006	08-Oct-2008	Now removing newline characters at the end of
44  
-"				the text. 
  51
+"				the text.
45 52
 "				Now, the register type is not modified by an
46  
-"				unconditional paste command. 
  53
+"				unconditional paste command.
47 54
 "				Now, multiple sequential newlines are converted
48  
-"				to a single space. 
49  
-"				Refactored s:FlattenRegister() to s:Flatten(). 
50  
-"	005	16-Jun-2008	Using :normal with <bang>. 
  55
+"				to a single space.
  56
+"				Refactored s:FlattenRegister() to s:Flatten().
  57
+"	005	16-Jun-2008	Using :normal with <bang>.
51 58
 "	004	30-May-2007	Added <silent> to the mapping to avoid echoing
52  
-"				of the function invocation. 
  59
+"				of the function invocation.
53 60
 "	0.03	13-May-2006	Changed mappings from <leader>.. to g.., as
54 61
 "				this is easier to type (and 'g' often introduces
55  
-"				alternative actions (like 'j' and 'gj')). 
  62
+"				alternative actions (like 'j' and 'gj')).
56 63
 "	0.02	10-Apr-2006	Added flattening (replacing newlines with
57  
-"				spaces) for characterwise paste. 
  64
+"				spaces) for characterwise paste.
58 65
 "	0.01	10-Apr-2006	file creation from vimtip #1199
59 66
 
60  
-" Avoid installing twice or when in unsupported Vim version. 
  67
+" Avoid installing twice or when in unsupported Vim version.
61 68
 if exists('g:loaded_UnconditionalPaste') || (v:version < 700)
62 69
     finish
63 70
 endif
@@ -66,81 +73,17 @@ let g:loaded_UnconditionalPaste = 1
66 73
 let s:save_cpo = &cpo
67 74
 set cpo&vim
68 75
 
69  
-function! s:HandleExprReg( exprResult )
70  
-    let s:exprResult = a:exprResult
71  
-endfunction
72  
-
73  
-function! s:Flatten( text )
74  
-    " Remove newline characters at the end of the text, convert all other
75  
-    " newlines to a single space. 
76  
-    return substitute(substitute(a:text, '\n\+$', '', 'g'), '\n\+', ' ', 'g')
77  
-endfunction
78  
-function! s:StripTrailingWhitespace( text )
79  
-    return substitute(a:text, '\s\+\ze\(\n\|$\)', '', 'g')
80  
-endfunction
81  
-
82  
-function! s:Paste( regName, pasteType, pasteCmd )
83  
-    let l:regType = getregtype(a:regName)
84  
-    let l:regContent = getreg(a:regName, 1) " Expression evaluation inside function context may cause errors, therefore get unevaluated expression when a:regName ==# '='. 
85  
-
86  
-    if a:regName ==# '='
87  
-	" Cannot evaluate the expression register within a function; unscoped
88  
-	" variables do not refer to the global scope. Therefore, evaluation
89  
-	" happened earlier in the mappings, and stored this in s:exprResult. 
90  
-	" To get the expression result into the buffer, use the unnamed
91  
-	" register, and restore it later. 
92  
-	let l:regName = '"'
93  
-	let l:regContent = s:exprResult
94  
-
95  
-	let l:save_clipboard = &clipboard
96  
-	set clipboard= " Avoid clobbering the selection and clipboard registers. 
97  
-	let l:save_reg = getreg(l:regName)
98  
-	let l:save_regmode = getregtype(l:regName)
99  
-    else
100  
-	let l:regName = a:regName
101  
-    endif
102  
-
103  
-    try
104  
-	let l:pasteContent = l:regContent
105  
-	if a:pasteType ==# 'c'
106  
-	    if l:regType[0] ==# "\<C-v>"
107  
-		let l:pasteContent = s:Flatten(s:StripTrailingWhitespace(l:regContent))
108  
-	    else
109  
-		let l:pasteContent = s:Flatten(l:regContent)
110  
-	    endif
111  
-	elseif a:pasteType ==# 'l' && l:regType[0] ==# "\<C-v>"
112  
-	    let l:pasteContent = s:StripTrailingWhitespace(l:regContent)
113  
-	endif
114  
-
115  
-	call setreg(l:regName, l:pasteContent, a:pasteType)
116  
-	execute 'normal! "' . l:regName . (v:count ? v:count : '') . a:pasteCmd
117  
-	call setreg(l:regName, l:regContent, l:regType)
118  
-    catch /^Vim\%((\a\+)\)\=:E/
119  
-	" v:exception contains what is normally in v:errmsg, but with extra
120  
-	" exception source info prepended, which we cut away. 
121  
-	let v:errmsg = substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', '')
122  
-	echohl ErrorMsg
123  
-	echomsg v:errmsg
124  
-	echohl None
125  
-    finally
126  
-	if a:regName ==# '='
127  
-	    call setreg('"', l:save_reg, l:save_regmode)
128  
-	    let &clipboard = l:save_clipboard
129  
-	endif
130  
-    endtry
131  
-endfunction
132  
-
133 76
 function! s:CreateMappings()
134 77
     for [l:pasteName, pasteType] in [['Char', 'c'], ['Line', 'l'], ['Block', 'b']]
135 78
 	for [l:direction, l:pasteCmd] in [['After', 'p'], ['Before', 'P']]
136 79
 	    let l:mappingName = 'UnconditionalPaste' . l:pasteName . l:direction
137 80
 	    let l:plugMappingName = '<Plug>' . l:mappingName
138 81
 	    execute printf('nnoremap <silent> %s :<C-u>' .
139  
-	    \	'silent! call repeat#setreg("\<lt>Plug>%s", v:register)<Bar>' .
  82
+	    \	'execute ''silent! call repeat#setreg("\<lt>Plug>%s", v:register)''<Bar>' .
140 83
 	    \	'if v:register ==# "="<Bar>' .
141  
-	    \	'    call <SID>HandleExprReg(getreg("="))<Bar>' .
  84
+	    \	'    call UnconditionalPaste#HandleExprReg(getreg("="))<Bar>' .
142 85
 	    \	'endif<Bar>' .
143  
-	    \	'call <SID>Paste(v:register, %s, %s)<Bar>' .
  86
+	    \	'call UnconditionalPaste#Paste(v:register, %s, %s)<Bar>' .
144 87
 	    \	'silent! call repeat#set("\<lt>Plug>%s")<CR>',
145 88
 	    \
146 89
 	    \	l:plugMappingName,

No commit comments for this range

Something went wrong with that request. Please try again.