12

At the moment I use C-xC-f to open a new file, but it gets quite tedious.

4
  • 1
    What's your goal? Opening a bunch of files at once? Or managing lots of already opened files?
    – viam0Zah
    Feb 19, 2010 at 11:02
  • 1
    Or do you just want to see multiple files at once? Because Emacs does keep all these files "open" (in a sense, they are loaded, but aren't "open" in a "file descriptor is open" sense). Feb 19, 2010 at 11:16
  • I want to edit several source files of a program
    – yazz.com
    Feb 19, 2010 at 11:17
  • Go thru this before using emacs Mar 13, 2017 at 18:09

4 Answers 4

20

When you load a file in Emacs with find-file (bound to Ctrl-x Ctrl-f by default), it gets put into a "buffer". As long as you don't kill the buffer, it stays in memory, you don't have to reload it.

You access already loaded files (buffers) with switch-to-buffer (bound to Ctrl-x b). Press the keys, then type the buffer name you want to switch to (by default that's the basename for any loaded file).

You can also press Ctrl-x Ctrl-b to get a list of currently existing buffers. And click any buffer there with the mouse to switch to it (IIRC, rarely use the mouse with Emacs ;-))

You can also split the screen in two (or more) parts to see different files (buffers) with Ctrl-x 2. Initially, this shows the same buffer twice. Switch to another buffer in one of the windows to see another file.

1
  • 1
    C-x 3 can also be used to split screen in two, C-x 0 to show only one buffer at once.
    – Rémi
    Oct 22, 2012 at 21:03
4

C-x b and C-x C-b are what you want. Also consider trying iswitchb or ido. Since I started using those I wish every program I used could switch tabs / windows / documents as quickly and conveniently as emacs. Often I have 50 files or more open in emacs, you can find the one you want very quickly with iswitchb or ido.

1

Also, if you are using a graphical version of emacs, you can do ctrl-x 5 b to open an existing buffer in a new window (called a frame in emacs-speak), or ctrl-x 5 f to load a new file in a new window.

3
  • 1
    c-x 5 b also works in a tty, but switching frames is annoying in tty mode :) Feb 19, 2010 at 15:41
  • @Justin Thanks. I've never played with frames in a tty. Is there any benefit over just using multiple buffers.
    – KeithB
    Feb 19, 2010 at 20:21
  • You can use frames vs windows the way you would use workspaces vs. windows in a Linux window manager - ie. for working on elisp code frame 1 has two windows, one with the info file for elisp, the other with ielm for interactively trying code, frame 2 has only one window, with whichever file you are editing (so you can get as many lines visible as possible it is unsplit). With a decent keybinding for other-frame it could be a very productive arrangement if you for some reason did not want to be running X. Feb 19, 2010 at 20:48
1

You can easily open multiple files at once (or act on them in other ways).

  1. Use C-x d to visit a directory (folder), which lists all of its files and subdirectories.

  2. Mark the files you want to open (or to act on in some other way). You can mark files individually or in groups based on various characteristics, including file-name patterns. See the menu-bar menus Mark and Regexp -- it shows you some available marking possibilities, as well as their keyboard shortcuts.

For example:

  • % m marks files whose names that match a regular expression.

  • % g marks files whose contents match a regular expression.

  • * * marks executable files.

To open all of the marked files at once you need to have loaded standard library dired-x.el. Do M-x load-library dired-x or put (require 'dired-x) in your init file.

Then you can use F (dired-do-find-marked-files) to visit all of the marked files at once. Use C-x C-b to see a list of the open buffers, where you can choose among those file buffers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .