I waste a lot of time between Vim and Python. I find it too slow to manually copy-paste from Python to Vim and vice versa. A good broken example is:
%!python for i in xrange(25); print 6*i \n
How can you do such tweaks direcly in Vim? [Solved]
[Clarification] I need things to Vim, like printing sequences, arithmetics... - things I cannot do in Vim.
[?] Can someone elaborate this point: "your script can read from stdin to operate directly on the lines given (., %, ...)."
[Further Clarification]
If I want to print 'Hello' to lines 4,5, 6 and 7, what is wrong:
:4-7!python -c "print 'hello'"
The dot . modifies the current line. Can I print on multiple lines 7, 32 and 99:
:7,32,99!python -c "print 'hello'"
Clearly not working. How?
Currently -python and -python3 seem to be the default for the Debian vim package. If you need vim support for scripting languages, install vim-nox , which is dedicated to them and therefore has (among other things) +python3 enabled.
Vim is an awesome text editor that can be used as a Python IDE. For those who use Vim and want to program in Python, here are a few tips on how to do it easily. Vim is a highly extensible text editor.
You need to compile Vim yourself or get a prebuilt Vim package that was compiled with Python support. If you're on a Debian based system, the easiest way is to download the vim-gnome or vim-gtk package from apt ( apt install vim-gtk for instance). Other distros might have a similar package with python support built in.
In any of your vim windows, type something like this:
for x in range(1,10): print '-> %d' % x
Visually select both of those lines (V to start visual mode), and type the following:
:!python
Because you pressed ':' in visual mode, that will end up looking like:
:'<,'>!python
Hit enter and the selection is replaced by the output of the print
statements. You could easily turn it into a mapping:
:vnoremap <f5> :!python<CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With