About: Evaluate current line using Python   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

See [help if_pyth.txt]. Below is a more elaborate example. Put the following code in your vimrc: python << EOL import vim # Do not say 'from vim import *' because that # will delete builtin function eval. def EvaluateCurrentLine(*args): cur_str = vim.current.line action, symb = None, None for i in args: if i in ["r","p"]: action = i else: symb = i try: start = cur_str.rindex(symb)+len(symb) except: start = 0 result = eval(cur_str[start:],globals()) if action == "r": vim.current.line = cur_str[:start]+str(result) else: print result EOL command -narg=* PyEv python EvaluateCurrentLine()

AttributesValues
rdfs:label
  • Evaluate current line using Python
rdfs:comment
  • See [help if_pyth.txt]. Below is a more elaborate example. Put the following code in your vimrc: python << EOL import vim # Do not say 'from vim import *' because that # will delete builtin function eval. def EvaluateCurrentLine(*args): cur_str = vim.current.line action, symb = None, None for i in args: if i in ["r","p"]: action = i else: symb = i try: start = cur_str.rindex(symb)+len(symb) except: start = 0 result = eval(cur_str[start:],globals()) if action == "r": vim.current.line = cur_str[:start]+str(result) else: print result EOL command -narg=* PyEv python EvaluateCurrentLine()
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 607(xsd:integer)
Category
  • Python
Author
  • Eugene M. Minkovskii
Complexity
  • intermediate
Created
  • 2003-11-24(xsd:date)
ID
  • 608(xsd:integer)
NEXT
  • 609(xsd:integer)
Rating
  • 9(xsd:integer)
abstract
  • See [help if_pyth.txt]. Below is a more elaborate example. Put the following code in your vimrc: python << EOL import vim # Do not say 'from vim import *' because that # will delete builtin function eval. def EvaluateCurrentLine(*args): cur_str = vim.current.line action, symb = None, None for i in args: if i in ["r","p"]: action = i else: symb = i try: start = cur_str.rindex(symb)+len(symb) except: start = 0 result = eval(cur_str[start:],globals()) if action == "r": vim.current.line = cur_str[:start]+str(result) else: print result EOL command -narg=* PyEv python EvaluateCurrentLine() Be careful about identation in the Python part. This code provides command: :PyEv This command evaluates expression in line under cursor and prints result in echo area. With r argument, it will evaluate the expression and be replaced by the result of evaluation: :PyEv r You can give one more argument - it will mark from which char in current line it should start evaluation. For example: Running the following command: :PyEv r { on the following line: \setlength{ extwidth}{450-63 will give: \setlength{ extwidth}{387
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software