How do I specify “the word under the cursor” on VIM's commandline?

前端 未结 8 962
后悔当初
后悔当初 2021-01-30 02:14

I want to write a command that specifies \"the word under the cursor\" in VIM. For instance, let\'s say I have the cursor on a word and I make it appear twice. For instance, i

8条回答
  •  鱼传尺愫
    2021-01-30 02:48

    @user11211 has the most straightforward way to duplicate the word under cursor:

    yiwP
    

    yank inner word (moves cursor to start of word), paste (before cursor).

    eg. straigh[t]forward ----> straightforwar[d]straightforward

    [] is cursor

    To elaborate...

    You probably want to have the cursor following your duplicated word:

    yiwPea
    

    straigh[t]forward ----> straightforwardstraightforward[]

    NOTE:

    yiw
    

    is yank inner word (without whitespace)

    yaw
    

    is yank all word (including trailing whitespace).

    yawPea
    

    is therefore duplicate word including whitespace, and position cursor.

    straigh[t]forward ----> straightforward straightforward[]

提交回复
热议问题