I have defined a python function in my .vimrc to use it on vim buffers in visual mode. The function has been vnoremap-ed to <F7>. Unfortunately, all the python output appears in the :messages of vim. Therefore, I would like to ask, if it possible to redirect the output to the current file @% instead. That is, I am looking for something of the sort :r!python ./some_function.py, used for calling regular python scripts and piping the output to the current file. The function I am using adds exactly two lines to the message block.
According to :help python
Vim displays all Python code output in the Vim message area. Normal
output appears as information messages, and error output appears as
error messages.
In implementation terms, this means that all output to sys.stdout
(including the output from print statements) appears as information
messages, and all output to sys.stderr (including error tracebacks)
appears as error messages.
Based on this, I can't imagine how this can be done and if it is possible at all. I will appreciate your help. Thank you
EDIT
The flowing code can serve as a minimal example. The following lines have to be included in ~/.vimrc
python << EOF
import vim
def sum_vals():
sum=sum(float_zero(v) for v in vim.eval('@"').splitlines() )
print("sum:>> %15.5E \n"%sum )
EOF
vnoremap <F7> y:python sum_vals()<Enter>
" An even simpler example
noremap <F8> :python print("hello world") <Enter>
Upon pressing <F7> the above function will yank the values in a visual selected column block and print their sum to the message block.
Pressing <F8> will on the contrary show the message hello world.
I would like to get the output of the above functions it in the current file instead of the :message block.
import vim; cb = vim.current.buffer; cb.append('line'); see the docs.:vnoremap <F7>mapping do? It's probably possible to adapt it to paste the output somewhere in the buffer, but to tell you how to adapt it, I guess we need to know what it's doing right now...<F8>will show the messagehello world