令我头大的编码风格: if(3 <= fun(x) || 6 >= fun(y)) {...}
与我的思维方式相反,每次都要改成: if(fun(x)>=3 || fun(y)<=6) {...}
这样,头才不晕!
每次都这样机械地改,很浪费时间,倒不如写个函数,绑定到v_x上
vmap x c
=XOperand(@") fun! XOperand(expr) let xMap = {'<':'>', '<=':'>=', '>':'<', '>=':'<=', '==':'=='} let mList = matchlist(a:expr,'^\s*\(.\{-}\)\s*\([<=>]=\?\)\s*\(.\{-}\)\s\{-}\n\?$') if len(mList) return mList[3].xMap[mList[2]].mList[1] else return a:expr endif
endfun
#选中 3 <= fun(x)
#按下 x
#变成 fun(x)>=3
反之亦然
延伸阅读
最新评论