Skip to content
Iury O. G. Figueiredo edited this page Dec 11, 2019 · 6 revisions

Execute Inline Python

Before dropping python commands to vy it is needed to set where the output should be printed. For such you need to use a keycommand. Place the cursor in the AreaVi instance that you want to drop the output of the python commands at the line.col then press:

<Tab> 

in NORMAL mode. It will show on the status bar that the output was redirected to that position.

After redirecting the output, you're done, just press:

<Alt-semicolon>

in Global mode. It will appear an input text widget where you can drop python commands to vy whose output will be dropped at the AreaVi instance position that you have set as output target.

Try inserting the following python code:

    print 'Hello from vy'

After you press enter, the AreaVi instance from where you issued the event in Global mode will regain the focus and the output from the command will be dropped at the position that you have set as output target.

Try now typing other commands like:

for ind in xrange(10): print ind;

Try picking up a different position where to drop python code output by pressing:

<Tab>

in NORMAL mode.

You will notice that it is possible to set different places where to drop python code output. It is particularly useful in some situations.

Set output targets

The default sys.stdout object is replaced by a new class that redirects the output of python code to AreaVi instances. It is possible to make output of python code be dropped over multiple AreaVi instances by switching the focus to the AreaVi instance then pressing

<Tab>

in NORMAL mode. Once an output target is added then a message at the statusbar will show the row and col at where python code output will be dropped.

Remove output targets

When it is no more needed to have output of python code dropped over a given AreaVi instance then switch the focus to the AreaVi instance and press:

<Control-Tab>

in NORMAL mode.

Restore the sys.stdout object

When it is needed to have the sys.stdout object restored to its default value, just press:

<Alt-Tab>

The command works in Global mode.

Set an AreaVi instance as target for commands

Some of vy plugins expose some functions/commands that work on the concept of an AreaVi target. Some functions operate on AreaVi instances, an example is the CPPaste() function that posts code onto codepad.org. Code that is executed using the key command below in Global mode it has the last AreaVi instance that had focus as target:

<Alt-semicolon>

But code that is executed from selected regions of text can have a different AreaVi instance as target to operate on. In order to set an AreaVi instance as target, press:

<Alt-z>

The msg 'Target set!' would appear on the status bar. Once the target is set then it is possible to execute python functions from selected regions of text that operate on the AreaVi instance that was set as target.

Try setting a command target then executing CPPaste() from other AreaVi instance with the following command in NORMAL mode after having selected the text 'CPPaste()':

<Key-semicolon>

Execute selected regions of python code

Select a region of text that corresponds to python code then switch to NORMAL mode and press:

<Key-semicolon>

The scope of plugin functions

It is possible to expose python functions to be executed through vy. These functions can perform all kind of tasks like posting code onto codepad or capitalizing selected text. These functions are implemented in modules that expose up in.

vyapp.plugins.ENV

When code is executed through the key commands below then it is executed in the dictionary shown above:

Clone this wiki locally