How can you use Python in Vim?

前端 未结 12 1821
清酒与你
清酒与你 2020-12-07 06:43

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:

%

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 07:37

    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  :!python
    

提交回复
热议问题