Reverse a word in Vim

前端 未结 10 1561
南方客
南方客 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:53

    if your version of VIM supports it you can do vw\is or viw\is (put your cursor at the first letter of the word before typing the command)... but I have had a lot of compatibility issues with that. Not sure what has to be compiled in or turned on but this only works sometimes.

    EDIT:

    \is is:

    :let old_reg_a=@a
    \ :let old_reg=@"
    \ gv"ay :let @a=substitute(@a, '.\(.*\)\@=', '\=@a[strlen(submatch(1))]', 'g') 
    \ gvca :let @a=old_reg_a 
    \ :let @"=old_reg
    

    Didn't remember where it came from but a google search come this article on vim.wikia.com. Which shows the same thing so I guess that's it.

提交回复
热议问题