This answers is written with Vim in mind. Some, all, or none of it may apply to your specific Vim emulator so YMMV.
First case
You can position your cursor on a_variable
and do:
ysiwfprint(<CR>
to obtain:
print(a_variable)
Second case
It is currently impossible to achieve with surround only.
Without surround
First case
You can position your cursor on a_variable
and do:
ciwprint(<C-r>")<Esc>
Second case
The scond case is a variant of the first case where you insert the variable name two times instead of one:
ciwprint("<C-r>": ", <C-r>")<Esc>
Turn it into a mapping if you need to do it often.
See :help c
, :help iw
, :help i_ctrl-r
, :help ""
.