How do I cut and paste between different files using emacs?

8,576

Solution 1

As far as I know, emacs has no idea that a completely different instance of emacs is running in a separate Terminal.app window. You need to use the Mac's Cmd-C and Cmd-V.

I could be wrong, perhaps emacs can be set up to use some form of IPC to find other separate running instances of emacs and try to share things like clipboards between them, but that seems unusual.See @IvanAndrus' Answer for how to use emacsclient to have emacs instances work together.

If you want emacs in separate GUI windows, you might also look at Aquamacs.

Updated to add: You could also learn to use emacs' native ability to edit multiple files/buffers within the same instance: http://www.gnu.org/software/emacs/manual/html_node/emacs/Buffers.html

Solution 2

You can (and should) use emacsclient if you want to use emacs in another terminal window (or even on a remote server). Then you'll be running the same emacs session in both terminals and copy/paste will work correctly. You can also combine this with GUI sessions. You do have to start the server in your .emacs file.

On this EmacsWiki page there are many examples of how to write scripts which will start an Emacs session if one isn't already running or connect to it if it's started. You may also want to try running Emacs as a daemon so that Emacs will keep running even though you have disconnected all your terminals.

Share:
8,576

Related videos on Youtube

Jim
Author by

Jim

Updated on September 18, 2022

Comments

  • Jim
    Jim over 1 year

    I'm running OSX 10.6.8. Lets say I have two terminal windows open and in each window I begin editing a different file using emacs. In the first file I select some text and then copy it (M-w), and in the second file I then try and paste it (C-y). I thought this would paste what I copied from the other file but instead I get the error message "previous command was not a yank".

    Those commands work just fine for copying and pasting within a single file, how do I copy and paste between different files?

  • Ivan Andrus
    Ivan Andrus about 12 years
    You can (and should) use emacsclient if you want to use emacs in another terminal window. Then you'll be running the same emacs session in both terminals and copy/paste will work correctly.
  • Spiff
    Spiff about 12 years
    @IvanAndrus Please post that as an Answer. I might keep my Answer up to give people other options to consider, but I think your answer is more in the spirit of what JStarx was trying to do.
  • Jim
    Jim about 12 years
    It was what I was trying to do, but I wasn't aware I could open more than one file! Thanx.