Copy and Paste Without Mouse in Console Editors

For a general overview of copy and paste in Linux, visit this page.

Joe

In joe to copy and paste, you must first mark the block. This is similar to hilighting with the mouse.

  • Move the cursor to the beginning of the text you wish to highlight
  • Press “Ctrl-k b” (for beginning).
  • Move the cursor to the end of the text you wish to copy
  • Press “Ctrl-k k”.
  • Move the cursor to the spot where you wish to copy the text to
  • Press “Ctrl-k c” for copy).

If you press “Ctrl-k m” instead, you move the text rather than simply copying it.

You can open more than one file in joe and copy and paste from one file to the next.

  • Open both files: 'joe file1 file2'
  • There will be a split screen with one file in each.
  • Press “Ctrl-k n” to move down to the next window
  • Press “Ctrl-k p” to move up to the previous window
  • Mark the block of text you want to copy. Move to the other file and paste.

Another sort of copy and paste is to insert a file into the current text.

  • Press “Ctrl-k r” followed by the name of the file.

The contents of the file will be placed at the cursor of the file you are editing.

Vi/Vim

With vi you do “yank” and “put.” When you open the file in vi, you are in command mode. If you have already entered Insert mode prior to the copy and paste, you will need to first go into Command mode again. ESC key gets you there.

  • Go to the line you want to begin copying
  • Count the number of lines you want to copy
  • Type '#y' where # is the number of lines to 'yank' or copy the lines.
  • Move the cursor to where you want to paste and type “p” for put (paste).

In vi you can have more than one file open at a time in split windows. That way you can yank and paste from one file to another.

  • Open your files “vi file1 file2”
  • Make a new windows “Ctrl-W, n”.
    • That puts you into the new window which is blank.
  • Open up the other file in that window with ”:n” (new file).

To copy and paste from one file to the other

  • Move from window to window with “Ctrl-W, W”
  • Yank the text you want
  • Go to the file you want to put it in
  • Type “p” to paste it into the other file.

Emacs

My favorite way of copying text in emacs is by means of the “kill-ring”.

To delete a line in emacs, press ctrl-k (“kill”). Press it twice, and the cr/lf-character that marks the line-end will also be killed. But the data you kill is not discarded right away. It is stored in the so called “kill-ring”. Thus you can think of it as the “cut” command in GUI-applications.

Ctrl-y (“yank”) then inserts the contents of the kill-ring into the file at the current cursor position. You can yank the same kill-ring multiple times at different positions in the file.

The kill-ring is emptied if you kill something after moving the cursor.

After a short while of practicing, you will be able to perform cut, copy and paste operations just as quick as with the mouse in a GUI.

There is a way of marking regions and cut/copy/paste them in emacs, but I never use them. I just love the kill-ring. :)

/home/www/LinuxBasics.org/data/pages/tutorials/using/editors/copy_paste.txt · Last modified: 2008/07/20 21:08 (external edit)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0