macros - An easy way to center text between first and last non-white word in vim? -
is there easy way using macro or ~10 line function (no plugin!) center text between first , last word (=sequence of non-blank characters) on line? e.g. turn
>>> no user serviceable parts below. <<<
into
>>> no user serviceable parts below. <<<
by balancing spaces +/-1? can assume no tabs , result should not contain tabs, note first word may not start in column 1. (edit: ... in fact, both delimiter words start , end of text center may on arbitrary columns.)
source function:
fun! centerinspaces() let l = getline('.') let lre = '\v^\s*\s+\zs\s*\ze' let rre = '\v\zs\s*\ze\s+\s*$' let sp = matchstr(l,lre) let sp = sp.matchstr(l,rre) let ln = len(sp) let l = substitute(l,lre,sp[:ln/2-1],'') let l = substitute(l,rre,sp[ln/2:],'') call setline('.',l) endf
note
this function might not work in cases. wrote quick usual case. not plugin after all
the codes lines reduced combining function calls. think clear in way, leave this.
if worked you, create map
it works this: (last 2 lines typed
@:
repeat cmd call)
Comments
Post a Comment