Wikia

Vim Tips Wiki

Changes: Unconditional linewise or characterwise paste

Edit

Back to page

(adjust previous/next navigation + minor manual clean)
(Reviewed, incorporated merged tip.)
 
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1199
 
|id=1199
Line 27: Line 26:
 
</pre>
 
</pre>
   
==Content from tip 1306 (now removed; content to be merged here)==
+
The above will keep newlines inside the register. To additionally join the pasted lines to a stream of characters without any newlines, use this:
{{Todo}}
 
*Might keep both these approaches, with clear guidance about why each is useful.
 
*Or, might merge them.
 
 
When you've yanked a text linewise, you can paste it in the middle of another line characterwise and joined. For example: yank 3 lines with <tt>3Y</tt>, move cursor into some other line, do <tt>\P</tt>.
 
   
 
<pre>
 
<pre>
Line 43: Line 42:
 
==See also==
 
==See also==
 
*[[VimTip356]] Quick yank and paste (will be "copy/paste mappings" tip)
 
*[[VimTip356]] Quick yank and paste (will be "copy/paste mappings" tip)
  +
  +
==Related Plugins==
 
*{{script|id=3355|text=UnconditionalPaste}} enhanced plugin based on this tip
 
*{{script|id=3355|text=UnconditionalPaste}} enhanced plugin based on this tip
   

Latest revision as of 07:17, June 17, 2012

Tip 1199 Printable Monobook Previous Next

created 2006 · complexity basic · author cory · version 6.0


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). This function and mapping will allow you to do a linewise or characterwise paste no matter how you yanked the text.

function! Paste(regname, pasteType, pastecmd)
  let reg_type = getregtype(a:regname)
  call setreg(a:regname, getreg(a:regname), a:pasteType)
  exe 'normal "'.a:regname . a:pastecmd
  call setreg(a:regname, getreg(a:regname), reg_type)
endfunction
nmap <Leader>lP :call Paste(v:register, "l", "P")<CR>
nmap <Leader>lp :call Paste(v:register, "l", "p")<CR>
nmap <Leader>cP :call Paste(v:register, "v", "P")<CR>
nmap <Leader>cp :call Paste(v:register, "v", "p")<CR>

The above will keep newlines inside the register. To additionally join the pasted lines to a stream of characters without any newlines, use this:

function! PasteJointCharacterwise(regname, pastecmd)
  let reg_type = getregtype(a:regname)
  call setreg(a:regname, '', "ac")
  exe 'normal "'.a:regname . a:pastecmd
  call setreg(a:regname, '', "a".reg_type)
  exe 'normal `[v`]J'
endfunction
nmap <Leader>p :call PasteJointCharacterwise(v:register, "p")<CR>
nmap <Leader>P :call PasteJointCharacterwise(v:register, "P")<CR>

See alsoEdit

  • VimTip356 Quick yank and paste (will be "copy/paste mappings" tip)

Related PluginsEdit

CommentsEdit

Around Wikia's network

Random Wiki