As a new user, you'll probably want to launch Emacs just to messaround and try it out. Once you're into Emacs and want to exit,however, you may not be able to figure out what to do. So if you'venever used Emacs before, give it a shot right now. At your shellprompt, type
emacs and hit enter. Emacs should start up. Ifnot, it is either not installed or not in your path.
Once you've seen Emacs, you need to know how to exit. Thekeystrokes for leaving Emacs are
C-x C-c. The
C-xnotation means hold down the
Ctrl key and press
x. In this case, you'll then need to hold down
c to finish the task.
The keystrokes used in Emacs will likely seem odd, foreign, andmaybe even uncomfortable to you at first--especially if you're a
vi user. Unlike
vi, Emacs doesn't have separatemodes for editing text and issuing commands.
emacs will start Emacs.
C-x C-c willexit Emacs.
What you'll see
When Emacs starts up it will consume a whole X window (or screen ifyou're running on a console instead of in the X Window System). You'llsee a menu across the top, some text in the main part of the screen,and a couple of lines at the bottom.
It will look something like this ASCII sketch:
+----------------------------------------------------------------------+|Buffers Files Tools Edit Search Mule Help || ||Welcome to GNU Emacs, one component of a Linux-based GNU system. || || || || ... || ||---1:---F1 *scratch* (Lisp Interaction)--L1--All-------------||For information about the GNU Project and its goals, type C-h C-p. |+----------------------------------------------------------------------+
NOTE: Emacs will usually fill the entirescreen/window. I've shrunk the above example to save space here. Youwill also see a welcome message in Emacs when you first start it. Iomitted that as well and substituted ``
...'' instead. Thewelcome message simply identifies the exact version of Emacs you areusing as well as pointing you to the on-line help and related items.
The Menu Bar
The topmost line of the Emacs interface is a menu. If you'rerunning X, you'll recognize them as traditional pull-down menus thatyou can access using your mouse. Otherwise you'll need to use keyboardshortcuts (not covered here) for accessing the menus.
The Status Bar and Mini-buffer
Of the last two lines in the Emacs interface, the topmost one isessentially a status bar. It contains information about the bufferyou're working in, which mode Emacs is in, and various otherthings. For now, just realize that it's there.
The bottommost line is called the mini-buffer. It isseparated from the main buffer by the status bar we justdiscussed. You can think of the mini-buffer as the Emacs``command-line''. It is where commands that you give Emacs appear andit is where status messages are printed in response to things you do.
You'll find that what I've called the status bar is usually referredto as the mode line in Emacs related documentation. It is where Emacsdisplays information about the current modes(s) you may be using aswell as things like the current date and time, line number, file size,and almost anything else you might want to see there.
This section covers the most basic of Emacs terminology that you'llencounter when using and reading about Emacs.
Buffers & Files
Unlike some editors, when you open a file in Emacs it does not stay``open'' the entire time you're working with it. Instead, Emacs readsthe file into a buffer in memory. While you're editing thebuffer and working with the data nothing is changed on disk. Only whenyou actually save the buffer does the file on disk get updated. Thereare advantages and disadvantages to this approach but it is onlyimportant that you understand that it works this way.
As a consequence, you will see the term ``buffer'' used in Emacsdocumentation, modes, packages, and so on. Just realize that buffermeans ``a copy of the file that is currently in memory.'' Oh, it'sworth pointing out that a buffer doesn't always have to refer to aspecific file on disk. Often times Emacs will create buffers as theresult of commands you run. Such buffers may contain the result of thecommand, a list of selections to pick from, and so on.
Point & Region
In Emacs lingo, you'll often hear or see references to thepoint. In general terms the point is the cursor. The actualdistinction between the point and cursor probably isn't important whenyou're first starting out with Emacs. But if you are curious, thinkabout it this way. The cursor is the visual representation of thepoint. The cursor is always ``on'' a particular character position inthe current buffer. The point, on the other hand, lives in the spacebetween characters on in the buffer. So you might say that ifthe cursor is on the letter `h' in the word ``the'' then the point isbetween the `t' and the `h'.
Like many modern editors, Emacs allows to perform operations(indent, spell-check, reformat, cut, copy, paste, ...) on a section ofthe current buffer. You can highlight (or ``mark'') a block of textusing the keyboard or mouse and then perform operations on just theselected block of text. In Emacs, that block of text is called aregion.
Okay, this will be a bit confusing to anyone who has ever used aGUI interface before. Just remember that Emacs was developed longbefore GUI interfaces and window managers were popular.
A window in Emacs is an area of the screen in which abuffer is displayed. When Emacs is first started, you have one windowon your screen. Some Emacs functions (such as the help anddocumentation) often [temporarily] open up additional windows in yourEmacs screen.
Emacs windows have nothing to do with X windows in the GUIsense. You can open up additional X windows to display Emacs buffers,maybe to compare two files side by side. Those new X windows arereferred to as frames in Emacs lingo. Read on.
In Emacs, a frame is a separate X window in which an Emacsbuffer is displayed. But both are part of the same Emacs session. Thebehavior is somewhat (but not too much) like what happens if you hitAlt+N in Netscape Navigator.
This section covers the basics of keyboarding for Emacs. Like everypowerful editor, everything that you can do with Emacs is just a fewkeystrokes away.
If you're a
vi user, the notion of using the
k, j, l,h keys to move up a line, down a line, forward by a character,and backward by a character probably took some getting used to. Infact, it might have taken you a few hours or even weeks of practicebefore you could comfortably navigate a file using the various keycombinations available in
Emacs is no different. There are different keystrokes and commandsto learn. Just like
vi, you only need to master the basics toget a lot of work done. Then, as time goes on, you can slowly expandyour knowledge and find faster ways of doing things.
Command Keys (Meta, Esc, Control, and Alt)
As you'll soon learn, Emacs makes heavy use of multi-keycombinations. Because it is not a modal editor like
vi, youdon't have to think about being in ``command mode'' or ``editingmode'' before you can try to move the cursor or execute acommand. Instead, you just press the right combination of keys andEmacs does as told (usually).
The keys that Emacs makes the most use of are usually abbreviated inthe documentation as
C (for Control or Ctrl) and
Mfor (Meta). While most modern PC keyboards have one or more keyslabeled
Ctrl few have one labeled
Meta. You'll wantto mentally substitute either
Alt for the Metakey. In most standard configurations, both Esc and Alt do essentiallythe same thing.
So when you see a reference in any Emacs related documentation to
C-x f it means ``press control-x and then f.'' And if you seea reference to something like
M-x shell is means ``pressalt-x and type the word shell''.
A very useful command for beginners is
M-x apropos or
C-h a. apropos will search the Emacs on-line documentationfor all functions and search for the regular expression you type. Thisis a great way to discover all commands related to frames. Simply
C-h a and then
Moving Around in a Buffer
Now that you know what all those fancy abbreviations mean, here's alist of the most common keystrokes for moving within a buffer:
Keystrokes Action-----------------------------------C-p Up one lineC-n Down one lineC-f Forward one characterC-b Backward one characterC-a Beginning of line C-e End of lineC-v Down one pageM-v Up one pageM-f Forward one wordM-b Backward one wordM-< Beginning of bufferM-> End of bufferC-g Quit current operation-----------------------------------
And, as you might expect, the cursor keys (or arrow keys) usuallywork just as you'd expect. Your
Backspace may not. That'sanother story.
Okay, now that you know how to move around within a buffer whatabout opening and saving files? Search? Here are some basic commands.
Before we jump straight to those commands, I need to briefly pointout how this works.
All ``command keystrokes'' in Emacs (those that are
C-something) are actually just shortcuts tofunctions which are part of Emacs. You can call any of those functionsby typing
M-x function-name and hitting
Enter. Youcan also use the keyboard shortcut for that function (if it has one).
For example, the Emacs function which saves a buffer to disk iscalled
save-buffer. By default it is also bound to
C-xC-s. So, you can either use they shortcut to save the currentbuffer, or you could type
M-x save-buffer and achieve theexact same result.
All of the most common functions have keyboard shortcuts bydefault. Some of them are listed below.
Keystrokes Function Description-------------------------------------------------------------------C-x C-s save-buffer Save the current buffer to diskC-x u undo Undo the last operationC-x C-f find-file Open a file from diskC-s isearch-forward Search forward for a stringC-r isearch-backward Search backward for a string replace-string Search & replace for a string replace-regexp Search & replace using regexpC-h t help-with-tutorial Use the interactive tutorialC-h f describe-function Display help for a functionC-h v describe-variable Display help for a variableC-h x describe-key Display what a key sequence doesC-h a apropos Search help for string/regexpC-h F view-emacs-FAQ Display the Emacs FAQC-h i info Read the Emacs documentationC-x r m bookmark-set Set a bookmark. Useful in searchesC-x r b bookmark-jump Jump to a bookmark.-------------------------------------------------------------------
As you try many of those functions, you'll notice that many willprompt you for input. They will always to do in the mini-buffer. Thisis similar to using the
: commands in
vi or mostcommands that you'd use within your favorite Unix shell.
Emacs has literally hundreds of built-in functions available. Thelist above is a tiny sample that represents those that I useregularly. See the on-line help for a more complete listing of theavailable functions and more complete documentation on those Imentioned above.
Like many popular Unix shells (bash, csh, tcsh, ...) Emacs offerscommand completion via the
Tab key. In fact, the commandcompletion in bash was modeled after that in Emacs, so if you use thatfeature in bash you'll be right at home.
As an example, try
M-x search and then hit
Tab. Emacs will append a hyphen to indicate that there areseveral possible completions but they all have a hyphen as the nextcharacter. Hit
Tab once more and Emacs will display a list ofthe possible matches for you to choose from. Notice that it does so ina new window. It temporarily splits your display into twowindows: one which contains the buffer you were editing and the othercontains the list of possible completions for ``search-''. You may hit
C-g to exit out of the selection process and close the newwindow.
Emacs comes with an on-line tutorial which walks you through thebasic editing features and functions that everyone should know. Italso explains how to use the other help features in Emacs.
I highly recommend that you spend some time going through thetutorial if you plan on making a serious effort to learn Emacs. Asshown in the table above, you can enter the tutorial via
C-ht. The tutorial is self-guided and aimed at folks who are justgetting started with Emacs.
If you are running Emacs in X, you will see that the rightmost menuon the menu bar is labeled Help. As you explore the Help menu noticethat some items have keyboard shortcuts and those are listed right inthe menu.
Finally, to see the volume of documentation available with Emacs,you should try
M-x info or
C-h i which launchesInfo, the Emacs documentation browser.
So if you've never used Emacs before, give it a shot right now. At your shell prompt, type emacs and hit enter. Emacs should start up. If not, it is either not installed or not in your path.How do I run Emacs commands? ›
You can run any Emacs command by name using M-x , whether or not any keys are bound to it. If you use M-x to run a command which also has a key binding, it displays a message to tell you about the key binding, before running the command.What does C stand for in Emacs? ›
C- means "control key", Hold down the control key while. pressing the next key. M- means "meta key", (“Escape” in the lab, on other computers sometimes “Alt”).What is a buffer in Emacs? ›
Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.How long does it take to get good at Emacs? ›
My short answer is Yes it is worth taking 3-4 weeks of a diminishing productivity-hit to learn Emacs. Even if you decide you prefer a streamlined unix utility combo over Emacs for development you will derive from it an education widely applicable beyond the editor.Should beginners use Emacs or Vim? ›
Emacs is easier to learn since it has a more natural interface (for users familiar with GUI-based text editors). Since Vim has different editing modes, beginners find it a little harder to learn. The main difference between the two is speed.What does M stand for in Emacs? ›
The M stands for the Meta key, which you can emulate on most keyboards by pressing the Esc key. For more information on Emacs keystroke naming conventions, see How keystrokes are denoted in Emacs. The default function of M-x is the command execute-extended-command .How do I navigate to a file in Emacs? ›
Emacs makes a new buffer for each file that you visit. To visit a file, type C-x C-f ( find-file ) and use the minibuffer to enter the name of the desired file. While in the minibuffer, you can abort the command by typing C-g .Why do programmers use Emacs? ›
A graphical editor typically allows you to have several files open at once, in different ags. Emacs allows you to do a similar thing in a text-only interface. You can have a terminal window open within Emacs. You don't need to exit Emacs to run commands, and all editing actions are available in the terminal.What does Ctrl c do in Emacs? ›
Binding Ctrl+c and Ctrl+x to both copy and cut and emacs keys.
RMS says he “picked the name Emacs because E was not in use as an abbreviation on ITS at the time.” The first Emacs was a set of macros written in 1976 at MIT by RMS for the editor TECO (Text Editor and COrrector, originally Tape Editor and COrrector) under ITS (the Incompatible Timesharing System) on a PDP-10.How many buffer can you open at a time in Emacs? ›
At any time, one and only one buffer is selected. It is also called the current buffer.How many buffers can you have at a time in Emacs? ›
The number of buffers you can have really has no limit. Most of the time, only one or two buffers are displayed, but even if you can't see them, all the buffers you create in an Emacs session are still active. You can think of them as a stack of pages, with the one being displayed as the top page.What is the point function in Emacs? ›
Point is a special buffer position used by many editing commands, including the self-inserting typed characters and text insertion functions. Other commands move point through the text to allow editing and insertion at different places.What is the best way to learn Emacs? ›
Try the EmacsTutorial, or read one of the BooksAboutEmacs. Learn Emacs using its SelfDocumentation. Asking Emacs directly is the best way to get to know it.What is the disadvantage of Emacs? ›
High learning curve. The extensive customizability makes pair programming difficult. Documentation is scattered about and some of it is out of date. Too many package repositories.Why use Emacs evil mode? ›
Emacs Evil mode is an extensible Vi layer for Emacs. It adds a set of Vi(m) key bindings and features to Emacs which gives it a more modal feel, and lets you rely less on the pinky-accessed CTRL key when manipulating text.Is Emacs outdated? ›
Vim and Emacs aren't going anywhere anytime soon, no matter their antiquated status in modern development environments. IDEs will keep improving, keep launching, and serve an ever-growing segment of young developers who were never forced to thrive in Vim or Emacs environments.Why do people prefer Vim over Emacs? ›
Productivity and Editing Speed
File editing is usually faster with Vim than with Emacs because of Vim's purposely speed-driven interface. For example, cursor movement can be controlled through the H, J, K, and L keys in the normal mode.
Emacs is (Arguably) Easy to Learn
Rather than using your mouse to move the cursor around and navigate between files or shell prompts, you instead use keyboard commands. Emacs makes this transition relatively easy for new users. You can start in Emacs by using the arrow keys to jump between lines and characters.
Emacs is a text editor designed for POSIX operating systems and available on Linux, BSD, macOS, Windows, and more. Users love Emacs because it features efficient commands for common but complex actions and for the plugins and configuration hacks that have developed around it for nearly 40 years.How do I write text in Emacs? ›
Inserting and deleting text
To insert text into a buffer, place the cursor where you want to start inserting text, and start typing away. If you want to insert the contents of another file into the current buffer, place the cursor at the desired insertion point, and type Control-X-I.
Versions of macOS prior to 10.15 Catalina include a copy of GNU Emacs 22 without GUI support compiled in and thus Emacs is automatically available on all but the most recent versions of macOS via the terminal. On macOS 10.15 Catalina and higher, mg (previously known as microGNUemacs) is still included.What is Emacs God mode? ›
This is a global minor mode for entering Emacs commands without modifier keys. It's similar to Vim's separation of command mode and insert mode. All existing key bindings will work in God mode. It's only there to reduce your usage of modifier keys.Which key is the Meta key? ›
On Windows the META key is the Window (⊞) key. On Mac machines the META key is the Cmd (⌘) key.How do I back one word in Emacs? ›
The keybindings for movement by word in Emacs is almost the same as that of movement by character, but instead of the prefix C- it is M- . To move forward one word use M-f ; and to move backward one word use M-b .How do I edit a file in Emacs? ›
The emacs editing mode is entered when you enable either the emacs or gmacs option. The only difference between these two modes is the way each handles the Ctrl-T edit command. To edit, move the cursor to the point needing correction and insert or delete characters or words, as needed.How do I save and exit in Emacs? ›
Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s. Users can also save the current buffer to some other file name by hitting the keys Ctrl + x, followed by Ctrl + w.How to use R in Emacs? ›
Start up Emacs without a file argument - just type emacs & at the prompt. Now execute R-mode - enter M-x R Think of M-x as `execute' and `R' for R. Emacs will then ask you for your R Starting Directory - enter the directory where you want to create a new (or open an already existing one) .Why is Emacs so complicated? ›
Emacs is extensible, and tends to collect many extensions into the main distribution over time. There has been a lot of time for that to happen, since Emacs is also so old. There are a lot of those extensions. That makes it complicated.
Emacs is a Text Editor which can morphed into any tool. Everything can be done inside it and can be done using only keyboard.How do you jump to a line in Emacs? ›
But if you indeed need to go to a certain text line, type M-g M-g (which is the default binding of the goto-line function). Emacs will prompt you for the number of the line and go to that line. You can do this faster by invoking goto-line with a numeric argument that is the line's number.How do you go to the end of a line in Emacs? ›
Unlike C-n and C-p , most of the Emacs commands that work on lines work on logical lines. For instance, C-a ( move-beginning-of-line ) and C-e ( move-end-of-line ) respectively move to the beginning and end of the logical line.How do I jump to the bottom in Emacs? ›
Type C-x o ("o" for "other") to move the cursor to the bottom window. >> Use C-v and M-v in the bottom window to scroll it.Is Emacs faster than mouse? ›
Emacs uses keyboard commands. This is faster than mouse commands. (The console version also offers menus, but you can edit faster without using them.)Which Emacs is best? ›
- Magit. Magit provides a complete, text-based Git integration solution directly into Emacs. ...
- Tabnine AI-powered development partner. ...
- Evil. ...
- Projectile. ...
- Sunrise-commander. ...
- Goto-last-change. ...
- Minimap. ...
- Visual Studio Code.
- Sublime Text.
The maximum buffer size on 32-bit machines is 512 MBytes beginning with version 23.2. If Emacs was built using the --with-wide-int flag, the maximum buffer size on 32-bit machines is 2 GB. Emacs compiled on a 64-bit machine can handle much larger buffers; up to most-positive-fixnum (2.3 exabytes).What is the difference between buffer and window in Emacs? ›
In brief: "Frames" are to Emacs what "windows" are to everything else. "Windows" are subdivisions of frames (think "window panes") "Buffers" hold the contents you display/edit in windows.
If the Emacs session has frames open on other graphical displays or text terminals, those are not deleted. The C-x 5 o ( other-frame ) command selects the next frame on the current terminal.What is the maximum integer in Emacs? ›
The range of values for an integer depends on the machine. The range is -8388608 to 8388607 (24 bits; i.e., to on most machines, but on others it is -16777216 to 16777215 (25 bits), or -33554432 to 33554431 (26 bits).
Emacs periodically saves all files that you are visiting; this is called auto-saving. Auto-saving prevents you from losing more than a limited amount of work if the system crashes. By default, auto-saves happen every 300 keystrokes, or after around 30 seconds of idle time.How do I open multiple files at once in Emacs? ›
- Ctrl-x 3 will split the screen horizontally.
- Ctrl-x 2 will split the screen vertically.
- Ctrl-x 1 closes all panes except the active one.
- Ctrl-x 0 closes a pane.
To access it, you can either use the menu by pressing F10 and press the RIGHT or LEFT arrow keys to select Help , or press the CTRL+H then a corresponding key. For example, you can enter one of the following keys after pressing CTRL+H to review FAQs, tutorials, news, and other topics: t to enter an Emacs Tutorial.How to play Emacs on terminal? ›
- emacs. Linux decided to install a GUI one 🤷🏽♂️
- emacs GUI. Press the escape then x keys, and M-x should appear at the bottom of the screen. Next, type in the name of the game you want to play. ...
- playing snake on emacs. You can quit emacs by pressing Ctrl-x Ctrl-c .