How can you use Python in Vim?

前端 未结 12 1785
清酒与你
清酒与你 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:28

    Can someone elaborate this point: "your script can read from stdin to operate directly on the lines given (., %, ...)."

    One common use is to sort lines of text using the 'sort' command available in your shell. For example, you can sort the whole file using this command:

    :%!sort
    

    Or, you could sort just a few lines by selecting them in visual mode and then typing:

    :!sort
    

    You could sort lines 5-10 using this command:

    :5,10!sort
    

    You could write your own command-line script (presuming you know how to do that) which reverses lines of text. It works like this:

    bash$ myreverse 'hello world!'
    !dlrow olleh
    

    You could apply it to one of your open files in vim in exactly the same way you used sort:

    :%!myreverse      <- all lines in your file are reversed
    

提交回复
热议问题