Skip to main content
Don't screw up q: etc.
Source Link
Antony
  • 2.6k
  • 12
  • 19
fun! QRepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QSetRepeat(_)
    set opfunc=QRepeat
endfun

fun! QStop()
    set opfunc=QSetRepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop QStop()
ino <expr> <plug>qstop "\<c-o>".QStop()

let s:qrec = 0
fun! QStart()
    if s:qrec == 1
        let s:qrec = 0
        return "q\<plug>qstop"
    endif
    let s:qrecqreg = 1nr2char(getchar())
    letif s:qreg =~# '[0-9a-zA-Z"]'
        let s:qrec = nr2char(getchar())1
    endif
    return 'q'.s:qreg
endfun

nmap <expr> q QStart()
fun! QRepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QSetRepeat(_)
    set opfunc=QRepeat
endfun

fun! QStop()
    set opfunc=QSetRepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop QStop()
ino <expr> <plug>qstop "\<c-o>".QStop()

let s:qrec = 0
fun! QStart()
    if s:qrec == 1
        let s:qrec = 0
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q QStart()
fun! QRepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QSetRepeat(_)
    set opfunc=QRepeat
endfun

fun! QStop()
    set opfunc=QSetRepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop QStop()
ino <expr> <plug>qstop "\<c-o>".QStop()

let s:qrec = 0
fun! QStart()
    if s:qrec == 1
        let s:qrec = 0
        return "q\<plug>qstop"
    endif
    let s:qreg = nr2char(getchar())
    if s:qreg =~# '[0-9a-zA-Z"]'
        let s:qrec = 1
    endif
    return 'q'.s:qreg
endfun

nmap <expr> q QStart()
remove useless line
Source Link
Antony
  • 2.6k
  • 12
  • 19
" When . repeats g@, repeat the last macro.
fun! AtAtAtRepeat(_)
    " If no count is supplied use the one saved in s:atcount.
    " Otherwise save the new count in s:atcount, so it will be
    " applied to repeats.
    let s:atcount = v:count ? v:count : s:atcount
    " feedkeys() rather than :normal allows finishing in Insert
    " mode, should the macro do that. @@ is remapped, so opfunc will'opfunc'
    " will be correct, even if the macro changes it.
    call feedkeys(s:atcount.'@@')
endfun

fun! AtNextAtSetRepeat(_)
    set opfunc=AtAtopfunc=AtRepeat
endfun

" Called by g@ being invoked directly for the first time. Sets
" 'opfunc' ready for repeats with . by calling AtNextAtSetRepeat().
fun! AtInit()
    " Make sure setting 'opfunc' happens here, after initial playback
    " of the macro recording, in case 'opfunc' is set there.
    set opfunc=AtNextopfunc=AtSetRepeat
    return 'g@l'
endfun

" Enable calling a function within the mapping for @
nno <expr> <plug>@init AtInit()
" A macro could, albeit unusually, end in Insert mode.
ino <expr> <plug>@init "\<c-o>".AtInit()

fun! AtReg()
    let s:atcount = v:count1
    let c = nr2char(getchar())
    return '@'.c."\<plug>@init"
endfun

nmap <expr> @ AtReg()
fun! QrepeatQRepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QsetrepeatQSetRepeat(_)
    set opfunc=Qrepeatopfunc=QRepeat
endfun

fun! QstopQStop()
    set opfunc=Qsetrepeatopfunc=QSetRepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop QstopQStop()
ino <expr> <plug>qstop "\<c-o>".QstopQStop()

let s:qrec = 0
fun! QstartQStart()
    if s:qrec == 1
        let s:qrec = 0
        set opfunc=Qstop
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q QstartQStart()
" When . repeats g@, repeat the last macro.
fun! AtAt(_)
    " If no count is supplied use the one saved in s:atcount.
    " Otherwise save the new count in s:atcount, so it will be
    " applied to repeats.
    let s:atcount = v:count ? v:count : s:atcount
    " feedkeys() rather than :normal allows finishing in Insert
    " mode, should the macro do that. @@ is remapped, so opfunc will
    " be correct, even if the macro changes it.
    call feedkeys(s:atcount.'@@')
endfun

fun! AtNext(_)
    set opfunc=AtAt
endfun

" Called by g@ being invoked directly for the first time. Sets
" 'opfunc' ready for repeats with . by calling AtNext().
fun! AtInit()
    " Make sure setting 'opfunc' happens here, after initial playback
    " of the macro recording, in case 'opfunc' is set there.
    set opfunc=AtNext
    return 'g@l'
endfun

" Enable calling a function within the mapping for @
nno <expr> <plug>@init AtInit()
" A macro could, albeit unusually, end in Insert mode.
ino <expr> <plug>@init "\<c-o>".AtInit()

fun! AtReg()
    let s:atcount = v:count1
    let c = nr2char(getchar())
    return '@'.c."\<plug>@init"
endfun

nmap <expr> @ AtReg()
fun! Qrepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! Qsetrepeat(_)
    set opfunc=Qrepeat
endfun

fun! Qstop()
    set opfunc=Qsetrepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop Qstop()
ino <expr> <plug>qstop "\<c-o>".Qstop()

let s:qrec = 0
fun! Qstart()
    if s:qrec == 1
        let s:qrec = 0
        set opfunc=Qstop
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q Qstart()
" When . repeats g@, repeat the last macro.
fun! AtRepeat(_)
    " If no count is supplied use the one saved in s:atcount.
    " Otherwise save the new count in s:atcount, so it will be
    " applied to repeats.
    let s:atcount = v:count ? v:count : s:atcount
    " feedkeys() rather than :normal allows finishing in Insert
    " mode, should the macro do that. @@ is remapped, so 'opfunc'
    " will be correct, even if the macro changes it.
    call feedkeys(s:atcount.'@@')
endfun

fun! AtSetRepeat(_)
    set opfunc=AtRepeat
endfun

" Called by g@ being invoked directly for the first time. Sets
" 'opfunc' ready for repeats with . by calling AtSetRepeat().
fun! AtInit()
    " Make sure setting 'opfunc' happens here, after initial playback
    " of the macro recording, in case 'opfunc' is set there.
    set opfunc=AtSetRepeat
    return 'g@l'
endfun

" Enable calling a function within the mapping for @
nno <expr> <plug>@init AtInit()
" A macro could, albeit unusually, end in Insert mode.
ino <expr> <plug>@init "\<c-o>".AtInit()

fun! AtReg()
    let s:atcount = v:count1
    let c = nr2char(getchar())
    return '@'.c."\<plug>@init"
endfun

nmap <expr> @ AtReg()
fun! QRepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QSetRepeat(_)
    set opfunc=QRepeat
endfun

fun! QStop()
    set opfunc=QSetRepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop QStop()
ino <expr> <plug>qstop "\<c-o>".QStop()

let s:qrec = 0
fun! QStart()
    if s:qrec == 1
        let s:qrec = 0
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q QStart()
naming
Source Link
Antony
  • 2.6k
  • 12
  • 19
fun! QdotQrepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! QnextQsetrepeat(_)
    set opfunc=Qdotopfunc=Qrepeat
endfun

fun! Qstop()
    set opfunc=Qnextopfunc=Qsetrepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop Qstop()
ino <expr> <plug>qstop "\<c-o>".Qstop()

let s:qrec = 0
fun! Qstart()
    if s:qrec == 1
        let s:qrec = 0
        set opfunc=Qstop
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q Qstart()
fun! Qdot(_)
    call feedkeys('@'.s:qreg)
endfun

fun! Qnext(_)
    set opfunc=Qdot
endfun

fun! Qstop()
    set opfunc=Qnext
    return 'g@l'
endfun

nno <expr> <plug>qstop Qstop()
ino <expr> <plug>qstop "\<c-o>".Qstop()

let s:qrec = 0
fun! Qstart()
    if s:qrec == 1
        let s:qrec = 0
        set opfunc=Qstop
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q Qstart()
fun! Qrepeat(_)
    call feedkeys('@'.s:qreg)
endfun

fun! Qsetrepeat(_)
    set opfunc=Qrepeat
endfun

fun! Qstop()
    set opfunc=Qsetrepeat
    return 'g@l'
endfun

nno <expr> <plug>qstop Qstop()
ino <expr> <plug>qstop "\<c-o>".Qstop()

let s:qrec = 0
fun! Qstart()
    if s:qrec == 1
        let s:qrec = 0
        set opfunc=Qstop
        return "q\<plug>qstop"
    endif
    let s:qrec = 1
    let s:qreg = nr2char(getchar())
    return 'q'.s:qreg
endfun

nmap <expr> q Qstart()
handle macro ending in Insert mode
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
replay macro immediately with dot
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
note about 'opfunc'
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
comments
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
explanation
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading
Source Link
Antony
  • 2.6k
  • 12
  • 19
Loading