Can vim's expression evaluation be used with existing expressions in the buffer? -


in vim, can quick calculations in either insert or command mode typing <c-r>= followed expression such 1.1+2.2, result buffer.

if have existing expression in current buffer, such 25.22 + 14.55, there way have vim evaluate expression, , replace result?

i interested in solutions not use external tools, such bc.

update: more explicit, here want on line in buffer before , after evaluation.

sample input:

25.22 + 14.55  

sample output:

39.77 

according documentation use eval() evaluate expression.

register                                                expr-register @r --------         ... when using '=' register expression itself, not evaluates to.  use eval() evaluate it. 

to pass current line eval() can use following.

:s/.*/\=eval(submatch(0)) 

which replaces expression result of running eval on it.

take @ :h sub-replace-expression


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -