Reverse a word in Vim

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

    Assuming you've got perl support built in to vim, you can do this:

    command! ReverseWord call ReverseWord()
    function! ReverseWord()
    perl << EOF
        $curword = VIM::Eval('expand("")');
        $reversed = reverse($curword);
        VIM::Msg("$curword => $reversed");
        VIM::DoCommand("norm lbcw$reversed");
    EOF
    endfun
    

    And potentially bind that to a keystroke like so:

    nmap ,r :ReverseWord
    

提交回复
热议问题