sponsor Vim development Vim logo Vim Book Ad

basic Tip #1306: Characterwise paste with auto join

 tip karma   Rating 6/3, Viewed by 852 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   August 14, 2006 5:15      complexity:   basic
author:   sply      as of Vim:   6.0

When you've yanked a text linewise, you can paste it in the middle of another line characterwise and joint. For example: yank 3 lines with 3Y, move cursor into some other line, do \P.

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>

Based on: vimtip #1199

 rate this tip  Life Changing Helpful Unfulfilling 

<< Define your own colours in gvim. | Link to Vince Negri 'conceal' patch for vim7 >>

Additional Notes

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo