Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ENH: Support smart adjustments on . through repeat.vim.

  • Loading branch information...
commit 9bf0a3295a00ac70e4e7d1649bc5197527f67c3a 1 parent 4a494e1
@inkarkat authored
Showing with 32 additions and 12 deletions.
  1. +4 −4 doc/smartput.txt
  2. +28 −8 plugin/smartput.vim
View
8 doc/smartput.txt
@@ -31,6 +31,9 @@ Smartput is a plugin, you can put it in a |plugin| folder of your
'runtimepath' or |:source| it directly. Typical locations:
~/.vim/plugin/smartput.vim (Unix) ~
{programs-folder}\vim\vimfiles\plugin\smartput.vim (Win)~
+Install the optional repeat.vim (vimscript #2136) plugin to enable the smart
+adjustments when repeating pastes with the |.| command.
+
Do not forget Smartput has been enabled (to not blame Vim for odd bugs you
might face ;-). I keep it on all the time and enjoy it most of the time ;-).
@@ -67,7 +70,7 @@ Standard put also applies if the register content is not characterwise!
Notes:
The "xp" trick is still supported (mentioned here: |usr_04|, search /xp ).
-When repeating the put, no adjustment takes place (of course).
+When repeating the put, no adjustment takes place unless you use repeat.vim.
When repeating a put-with-count, in some cases the repetition includes one
less instance of the put text. E.g. "3p." on an empty line with "abc" in the
@@ -298,9 +301,6 @@ Bugs:
inserted left from cursor
+ put with count doesn't work in empty line and at EOL without trailing
space
-+ 13-12-2007 You cannot repeat a put with the "." command. This is currently
- a limit in Vim, workarounds are difficult; feedkeys() might help, but it is
- not safe to use if commands follow.
+ 13-12-2007 Also the "1p........ trick doesn't work |redo-register|.
+ user should avoid 'virtualedit=onemore'
v0.6 16-12-2007
View
36 plugin/smartput.vim
@@ -80,10 +80,11 @@ endfunction
" Smartput: recognize words and adjust spaces and commas {{{1
function! <sid>Smartput(putcmd)
" putcmd: "P", "p", "gP" or "gp"
+ let s:putcmd = a:putcmd
let l:count = v:count1
let reg = v:register
if !s:enable || getregtype(reg) !=# 'v' || v:register =~ '[:.%#=_]'
- exe "nn <sid>put" l:count.'"'.reg.a:putcmd
+ exe "nn <script> <sid>put" l:count.'"'.reg.a:putcmd.'<sid>setrepeat'
return
endif
let put = getreg(reg)
@@ -91,13 +92,13 @@ function! <sid>Smartput(putcmd)
" keep the "xp" trick working:
if put =~ "^.$"
- exe "nn <sid>put" l:count.'"'.reg.a:putcmd
+ exe "nn <script> <sid>put" l:count.'"'.reg.a:putcmd.'<sid>setrepeat'
return
endif
let put = substitute(put, '^\s*\|\s*$', '', 'g')
if put == ""
- nn <sid>put <nop>
+ nn <script> <sid>put <sid>setrepeat
return
endif
@@ -191,7 +192,7 @@ function! <sid>Smartput(putcmd)
call cursor(curlnum, curcol+1-toofar)
call setreg(reg, put)
if asusual
- exe "nn <script> <sid>put" l:count.'"'.reg.putcmd."<sid>restore"
+ exe "nn <script> <sid>put" l:count.'"'.reg.putcmd."<sid>setrepeat<sid>restore"
else
" e.g. 3p -> p2p, 3P -> P2p, 3gp -> p2gp, 3gP -> P2gp
exe 'nn <sid>pone' '"'.reg.nogput."`]"
@@ -200,6 +201,11 @@ function! <sid>Smartput(putcmd)
endif
endfunction
+" SmartputRepeat: recognize words and adjust spaces and commas {{{1
+function! <sid>SmartputRepeat()
+ call s:Smartput(s:putcmd)
+endfunction
+
" Restore: Undo the temporary register modification {{{1
function! s:Restore()
call setreg(s:save_reg[0], s:save_reg[1])
@@ -207,6 +213,18 @@ function! s:Restore()
return ''
endfunction
+" SetCount: Store the count given by the user for repeating before the recursive call decreases it. {{{1
+function! s:SetCount()
+ let s:count = v:count1
+ silent! call repeat#setreg("\<plug>SmartputRepeat", v:register)
+endfunction
+
+" Repeat: Set up repeat.vim {{{1
+function! s:SetRepeat()
+ silent! call repeat#set("\<plug>SmartputRepeat", s:count)
+ return ''
+endfunction
+
" SmartputToggle: toggle mapping of P, p, gP, gp {{{1
function! s:SmartputToggle(arg)
" arg: "on":enable, "off":disable, "":toggle,
@@ -239,10 +257,10 @@ function! s:SmartputToggle(arg)
return
endif
if s:enable
- nn <script><silent> P :<c-u>call<sid>Smartput('P')<cr><sid>put
- nn <script><silent> p :<c-u>call<sid>Smartput('p')<cr><sid>put
- nn <script><silent> gP :<c-u>call<sid>Smartput('gP')<cr><sid>put
- nn <script><silent> gp :<c-u>call<sid>Smartput('gp')<cr><sid>put
+ nn <script><silent> P :<c-u>call<sid>SetCount()<bar>call<sid>Smartput('P')<cr><sid>put
+ nn <script><silent> p :<c-u>call<sid>SetCount()<bar>call<sid>Smartput('p')<cr><sid>put
+ nn <script><silent> gP :<c-u>call<sid>SetCount()<bar>call<sid>Smartput('gP')<cr><sid>put
+ nn <script><silent> gp :<c-u>call<sid>SetCount()<bar>call<sid>Smartput('gp')<cr><sid>put
" XXX using <expr> would be much easier but exclude too many older
" Vim7s with the count bug
else
@@ -264,7 +282,9 @@ endfunc
" Commands, Mappings, Inits: {{{1
com! -bar -nargs=? -complete=custom,s:SmaToCompl SmartputToggle call s:SmartputToggle(<q-args>)
nn <plug>SmartputToggle :SmartputToggle<cr>
+nn <script> <plug>SmartputRepeat :<c-u>call<sid>SetCount()<bar>call<sid>SmartputRepeat()<cr><sid>put
nn <silent> <expr> <sid>restore <sid>Restore()
+nn <silent> <expr> <sid>setrepeat <sid>SetRepeat()
if !hasmapto("<plug>SmartputToggle", "n")
try
Please sign in to comment.
Something went wrong with that request. Please try again.