Created
January 7, 2012 04:06
-
-
Save kien/1573750 to your computer and use it in GitHub Desktop.
Repeatable g, z, [ and ] mappings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Repeatable g, z, [ and ] mappings | |
nn <silent> g :<c-u>cal keycmd#init('g', v:register)<cr> | |
nn <silent> z :<c-u>cal keycmd#init('z', v:register)<cr> | |
nn <silent> [ :<c-u>cal keycmd#init('[', v:register)<cr> | |
nn <silent> ] :<c-u>cal keycmd#init(']', v:register)<cr> | |
nn <silent> _g :cal keycmd#repeat('g')<cr> | |
nn <silent> _z :cal keycmd#repeat('z')<cr> | |
nn <silent> _[ :cal keycmd#repeat('[')<cr> | |
nn <silent> _] :cal keycmd#repeat(']')<cr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" File: autoload/keycmd.vim | |
" Description: Make g, z, [ and ] mappings repeatable | |
fu! keycmd#init(...) | |
if a:1 !~# 'z\|g\|\[\|\]' | retu | en | |
let vpct = v:count ? v:count : '' | |
let char = nr2char(getchar()) | |
if ( a:1 == 'z' && char =~# 'f\|\d' ) | |
\ || ( a:1 == 'g' && char =~# "\\v'|`|U|\\?|q|r|u|w|\\@|\\~" ) | |
cal feedkeys(vpct.a:1.char, 'nt') | |
retu | |
en | |
let vreg = a:1 == 'g' && char =~? 'p' ? '"'.a:2 : '' | |
if !exists('s:rp') | |
let s:rp = {} | |
en | |
cal extend(s:rp, { a:1 : vpct.vreg.a:1.char }) | |
cal feedkeys(s:rp[a:1], 'nt') | |
endf | |
fu! keycmd#repeat(...) | |
if exists('s:rp') && has_key(s:rp, a:1) | |
cal feedkeys(s:rp[a:1], 'nt') | |
en | |
endf | |
" vim:nofen:noet:ts=2:sw=2:sts=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment