Vim: how do I swap two characters?

后端 未结 4 557
野性不改
野性不改 2021-02-03 17:23

Is there a fast command to change

Cnotrol

to

Control
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 17:32

    While in normal mode, with your cursor on top of the first character to swap, you can type xp to delete one character and put it after the cursor, effectively swapping the two characters.

    One possibly useful command (taken straight from the Vim page on swapping) would be

    :nnoremap  gc xph
    

    to map gc (or another command of your choice) to swapping two characters. Note that the h simply moves the cursor back to its original position, on top of the first of the two characters to be swapped.

提交回复
热议问题