How to copy lines

I just got this from a “Unix guru” tip list. How to copy a number of lines from one file to another using vi, the standard Unix/Linux editor:

Having loaded the source file into vi, do this:

  1. Press ESC
  2. Press Shift ” (Shift double quotes)
  3. Press a
  4. Press the number of lines you want to copy
  5. Press y followed by another y
  6. Press ” : ” (COLON) to get the vi prompt.
  7. Hit e followed by the destination filename
  8. Go to the line where you want the lines copied to be inserted.
  9. Press ESC.
  10. Press SHIFT ” (Double quotes).
  11. Press a.
  12. Press p.

This is how you copy a number of lines from one file to another in vi.

Of course, if you break it down in my favorite editor, it isn’t that much better:

  1. Put point (cursor) at the beginning of the text to be copied
  2. Press Ctrl-Space to mark the beginning
  3. Move point to the end of the text to be copied
  4. Press Meta-W to write the region into the “kill ring” without deleting it
  5. Switch to the other file (either by loading it using Ctrl-X Ctrl-F filename RET or switching to that buffer if you already loaded it)
  6. Put point where you want to insert the lines
  7. Press Ctrl-Y to yank the lines into their new home

If you’re using a GUI version of Emacs, though, it’s much simpler:

  1. Drag from the beginning of the text you want to copy to the end
  2. Load the file from the “File -> Open File” menu
  3. Middle-click where you want the text yanked

That, at least, doesn’t look so daunting. And the fact is, vi and Emacs aficionados could both probably accomplish the “long” versions more quickly than a novice could do it with a mouse, in any editor. Still, though, people wonder why we don’t have Linux on the desktop yet… and this could be part of it. Oh, well.

Then again, try this in Notepad under Windows:

  1. Drag from the beginning of the text you want to copy to the end
  2. Hit Ctrl-C or choose “copy” from the Edit menu
  3. Load a new file by choosing “Open” from the File menu
  4. Click once where you want to paste the lines from the old file
  5. Hit Ctrl-V or choose “paste” from the Edit menu

Maybe we are making progress.

Bad Behavior has blocked 891 access attempts in the last 7 days.