How to yank the text on a line and paste it inline in Vim?

前端 未结 4 1512
南笙
南笙 2020-12-23 11:12

Say, I have the following lines:

thing();
getStuff();

I want to take getStuff() using the yy command, go forward to

4条回答
  •  盖世英雄少女心
    2020-12-23 12:05

    One way to simplify the routine of operating on the same text patterns is to define mappings that mimic text-object selection commands.

    The two pairs of mappings below—one for Visual mode and another for Operator-Pending mode—provide a way to select everything on the current line except for the new line character (al), and everything from the first non-blank character of the current line through the last non-blank character, inclusively (il).

    :vnoremap  al :norm!0v$h
    :vnoremap  il :norm!^vg_
    :onoremap  al :norm val
    :onoremap  il :norm vil
    

    Thus, instead of using yy to copy the contents of a line that is to be pasted character-wise (and not line-wise), one can then use the yal or yil commands to yank, followed by the p command to paste, as usual.

提交回复
热议问题