Reverse a word in Vim

前端 未结 10 1525
南方客
南方客 2021-01-17 11:16

How can I reverse a word in Vim? Preferably with a regex or normal-mode commands, but other methods are welcome too:

word => drow

<
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 11:59

    Well you could use python itself to reverse the line through the filter command. Say the text you had written was:

    Python
    

    You could reverse it by issuing.

    :1 ! python -c "print raw_input()[::-1]"
    

    And your text will be replaced to become:

    nohtyP
    

    The "1" in the command tells vi to send line 1 to the python statement which we are executing: "print raw_input()[::-1]". So if you wanted some other line reversed, you would send that line number as argument. The python statement then reverses the line of input.

提交回复
热议问题