When Vim is compiled with Python support, you can script Vim with Python using the
:python command. How would I go about using this to execute the command and insert the result under the cursor? For example, if I were to execute
:python import os; os.listdir('aDirectory'), I would want the first filename returned to be inserted under the cursor.
EDIT: To clarify, I want the same effect as going to the terminal, executing the command, copying the result and executing
The following works fine for me: write the python code you want to execute in the line you want.
import os print(os.listdir('.'))
after that visually select the lines you want to execute in python
and after that the python code will replaced by the python output.
:,!python -c "import os; print os.listdir('aDirectory')"