Cut and paste multiple lines in vim

vim

I'm running vim 7.3 on a Mac 10.7.2 and I'm having some trouble cutting and pasting several lines.

On my old Linux setup (which was stolen so I don't know versions), I could type "dd" multiple times and then "p" would yank all of them back. For example: type: "dd dd" and two lines would be deleted. Now type "p" and both lines are pasted back into the buffer.

I know I can accomplish what I want by typing "2dd", and then "p" – but I would like to be able to "dd"-out lines without counting the number of lines ahead of time.

Any ideas?

Best Answer

Have you considered using visual mode?

You could just go:

  • Press V
  • Select everything you want to cut without counting
  • Press d
  • Go to where you want to paste
  • Press p

This should yield approximately half as many keystrokes as the dd method since you press one key per line rather than two. Bonus points if you use 5j (or similar) to select multiple lines at a time.