Permalink
Browse files

Improved visual mode pasting and respecting count (not fully though)

  • Loading branch information...
1 parent 8415af6 commit 4aa68713826951ac071f92fc8034e0cd0802c37f @sickill committed Nov 7, 2011
Showing with 22 additions and 7 deletions.
  1. +22 −7 plugin/pasta.vim
View
@@ -11,18 +11,33 @@ function! s:normal_pasta(p, o)
if (getregtype() ==# "V")
exe "normal! " . a:o . "\<space>\<bs>\<esc>\"" . v:register . "]pk\"_dd"
else
- exe "normal! \"" . v:register . a:p
+ exe "normal! " . v:count1 . '"' . v:register . a:p
endif
endfunction
-function! s:visual_pasta() range
- exe "normal! gv\"_c\<space>\<bs>\<esc>\"" . v:register . "]pk\"_dd"
+function! s:visual_pasta()
+ if (visualmode() ==# "V")
+ if (getregtype() ==# "V")
+ exe "normal! gv\"_c\<space>\<bs>\<esc>\"" . v:register . "]pk\"_dd"
+ else
+ exe "normal! gv\"_c\<space>\<bs>\<esc>\"" . v:register . "]p"
+ endif
+ else
+ " workaround strange Vim behavior (""p is no-op in visual mode)
+ if (v:register == '"')
+ let reg = ""
+ else
+ let reg = "\"" . v:register
+ endif
+
+ exe "normal! gv" . v:count1 . reg . "p"
+ endif
endfunction
-nnoremap <silent> P :call <SID>normal_pasta('P', 'O')<CR>
-nnoremap <silent> p :call <SID>normal_pasta('p', 'o')<CR>
+nnoremap <silent> P :<C-U>call <SID>normal_pasta('P', 'O')<CR>
+nnoremap <silent> p :<C-U>call <SID>normal_pasta('p', 'o')<CR>
-vnoremap <silent> P :call <SID>visual_pasta()<CR>
-vnoremap <silent> p :call <SID>visual_pasta()<CR>
+vnoremap <silent> P :<C-U>call <SID>visual_pasta()<CR>
+vnoremap <silent> p :<C-U>call <SID>visual_pasta()<CR>
" vim:set sw=2 sts=2:

0 comments on commit 4aa6871

Please sign in to comment.