A regex that comes close in pure vim is
vcs*zs(s{-}(((sqrt|log|sin|cos|tan|exp)?(.{-}))|(-?[0-9,.]+(e-?[0-9]+)?)|([-+*/%^]+)))+(s*=?)?s*
存在一些限制:低压(包括职能论点)为平价。 你们需要使用适当的克法教区来这样做,我不建议这样做。
Operator Mapping
To enable using this a bit like text-objects, use something like this in your $MYVIMRC:
func! DetectExpr(flag)
let regex = vcs*zs(s{-}(((sqrt|log|sin|cos|tan|exp)?(.{-}))|(-?[0-9,.]+(e-?[0-9]+)?)|([-+*/%^]+)))+(s*=?)?s*
return searchpos(regex, a:flag . ncW , line( . ))
endf
func! PositionLessThanEqual(a, b)
"echo a: . string(a:a)
"echo b: . string(a:b)
if (a:a[0] == a:b[0])
return (a:a[1] <= a:b[1]) ? 1 : 0
else
return (a:a[0] <= a:b[0]) ? 1 : 0
endif
endf
func! SelectExpr(mustthrow)
let cpos = getpos(".")
let cpos = [cpos[1], cpos[2]] " use only [lnum,col] elements
let begin = DetectExpr( b )
if ( ((begin[0] == 0) && (begin[1] == 0))
|| !PositionLessThanEqual(begin, cpos) )
if (a:mustthrow)
throw "Cursor not inside a valid expression"
else
"echoerr "not satisfied: " . string(begin) . " < " . string(cpos)
endif
return 0
endif
"echo "satisfied: " . string(begin) . " < " . string(cpos)
call setpos( . , [0, begin[0], begin[1], 0])
let end = DetectExpr( e )
if ( ((end[0] == 0) || (end[1] == 0))
|| !PositionLessThanEqual(cpos, end) )
call setpos( . , [0, cpos[0], cpos[1], 0])
if (a:mustthrow)
throw "Cursor not inside a valid expression"
else
"echoerr "not satisfied: " . string(begin) . " < " . string(cpos) . " < " . string(end)
endif
return 0
endif
"echo "satisfied: " . string(begin) . " < " . string(cpos) . " < " . string(end)
norm! v
call setpos( . , [0, end[0], end[1], 0])
return 1
endf
silent! unmap X
silent! unmap <M-.>
xnoremap <silent>X :<C-u>call SelectExpr(0)<CR>
onoremap <silent>X :<C-u>call SelectExpr(0)<CR>
现在,你可以围绕(或之后)曲线的位置进行最接近的表述:
- vX - [v]isually select e[X]pression
- dX - [d]elete current e[X]pression
- yX - [y]ank current e[X]pression
"a
yX - id. to register a
作为一种骗子,为了mo的目的,利用以下手段从被占领土上获得精确的乙 art(virtualed<>/em>):
Insert mode mapping
针对聊天:
" if you want trailing spaces/equal sign to be eaten:
imap <M-.> <C-o>:let @e=""<CR><C-o>"edX<C-r>=substitute(@e, ^v(.{-})(s*=?)?s*$ , =string(eval(submatch(1))) , )<CR>
" but I m assuming you wanted them preserved:
imap <M-.> <C-o>:let @e=""<CR><C-o>"edX<C-r>=substitute(@e, ^v(.{-})(s*=?s*)?$ , =string(eval(submatch(1))) . submatch(2) , )<CR>
允许你打上Alt-.,插入方式,目前的表述改为评价。 治疗器在结果结束时添加方式。
200 + 3 This is my text -300 +2 + (9*3)
This is text 0.25 + 2.000 + sqrt(15/1.5)
以“Alt-.为试验,插入3次:
203 This is my text -271
This is text 5.412278
For Fun: ascii art
vXoyoEsc`<jPvXr-r|e.
易于测试:
:let @q="vXoyox1b`<jPvXr-r|e.a*x1b"
:set virtualedit=all
Now you can @q anywhere and it will ascii-decorate the nearest expression :)
200 + 3 = 203 -300 +2 + (9*3) =
|-------|*
|-------------------|*
200 + 3 = 203 -300 +2 + (9*3)
|-----------------|*
|-------|*
This is text 0,25 + 2.000 + sqrt(15/1.5)
|-------------------------|*
1 consider using Vim s python integration to do such parsing