How to duplicate a whole line in Vim?

后端 未结 19 832
北海茫月
北海茫月 2020-12-22 14:29

How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+&

相关标签:
19条回答
  • 2020-12-22 14:52

    You can also try <C-x><C-l> which will repeat the last line from insert mode and brings you a completion window with all of the lines. It works almost like <C-p>

    0 讨论(0)
  • 2020-12-22 14:53

    For those starting to learn vi, here is a good introduction to vi by listing side by side vi commands to typical Windows GUI Editor cursor movement and shortcut keys. It lists all the basic commands including yy (copy line) and p (paste after) or P(paste before).

    vi (Vim) for Windows Users

    0 讨论(0)
  • 2020-12-22 14:54

    For someone who doesn't know vi, some answers from above might mislead him with phrases like "paste ... after/before current line".
    It's actually "paste ... after/before cursor".

    yy or Y to copy the line
    or
    dd to delete the line

    then

    p to paste the copied or deleted text after the cursor
    or
    P to paste the copied or deleted text before the cursor


    For more key bindings, you can visit this site: vi Complete Key Binding List

    0 讨论(0)
  • 2020-12-22 14:58

    YP or Yp or yyp.

    0 讨论(0)
  • 2020-12-22 14:58

    yy

    will yank the current line without deleting it

    dd

    will delete the current line

    p

    will put a line grabbed by either of the previous methods

    0 讨论(0)
  • 2020-12-22 14:59

    Another option would be to go with:

    nmap <C-d> mzyyp`z
    

    gives you the advantage of preserving the cursor position.

    0 讨论(0)
提交回复
热议问题