[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
slackbook:emacs [2012/08/20 15:53 (UTC)] – created kookiemonster | slackbook:emacs [2012/09/16 16:52 (UTC)] (current) – [Sources] updated authors and tags mfillpot | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Emacs ====== | ====== Emacs ====== | ||
+ | ===== What is Emacs? ===== | ||
- | While [[slackbook: | + | **//vi//** and its clones |
+ | and powerful editors. | ||
+ | particularly extensible. | ||
+ | successful | ||
+ | **//vi//** variant that shrugs this trend, | ||
+ | being both extremely extensible | ||
+ | users prefer | ||
+ | many people | ||
+ | **//Emacs//**. | ||
- | Also unlike vi, which is an (excellent) editor and nothing more, emacs is a program with near endless capabilities. emacs is (for the most part) written in Lisp, which is a very powerful programming language that has the peculiar property that every program written in it is automatically a Lisp compiler of its own. This means that the user can extend emacs, and in fact write completely new programs "in emacs" | ||
- | As a result, emacs is not just an editor anymore. There are many add-on packages for emacs available | + | Emacs takes extensibility up to eleven. |
+ | the rest of **// | ||
+ | Lisp variant, nearly all of which is exposed to you, so that you | ||
+ | may configure it or even extend it at will (many good Emacs Lisp | ||
+ | tutorials can be found on the Internet). People have written | ||
+ | all sorts of extensions in Emacs Lisp, from syntax highlighting | ||
+ | for an obscure language, to a built-in terminal. In fact, | ||
+ | there's even a **//vi//** emulation mode | ||
+ | within **// | ||
+ | can still get the modal editing that comes with vi, while having | ||
+ | access to the power of the **// | ||
+ | core. | ||
- | There are two main versions of emacs: GNU Emacs (which is the version that comes with Slackware) and XEmacs. The latter is not a version for Emacs running under X. In fact, both emacs and XEmacs run on the console as well as under X. XEmacs was once started as a project to tidy up the emacs code. Currently, both versions are being actively developed, and there is in fact much interaction between the two development teams. For the present chapter, it is immaterial whether you use emacs or XEmacs, the differences between them are not relevant to the normal user. | ||
- | ===== Starting | + | Like **//vi//**, there are many variants of |
+ | **//Emacs//** (termed //" | ||
+ | the one most commonly used (and the only one in Slackware) is | ||
+ | GNU Emacs. | ||
+ | always mean GNU Emacs. | ||
- | Emacs can be started from the shell by simply typing emacs. When you are running X, emacs will (normally) come up with its own X window, usually with a menu bar at the top, where you can find the most important functions. On startup, emacs will first show a welcome message, and then after a few seconds will drop you in the *scratch* buffer. (See Section 17.2.) | ||
- | You can also start emacs on an existing | + | Unlike **// |
+ | **// | ||
+ | traditional editor by default. | ||
+ | shortcuts can be performed without repeatedly changing modes. | ||
+ | You can open up a file and start typing | ||
+ | learn what the modes do, or forgetting which one you are | ||
+ | currently using. | ||
+ | ===== Starting Out ===== | ||
- | % emacs | + | **// |
- | /etc/resolv.conf | + | running the **//emacs//** command in your |
- | | + | terminal. |
+ | you first start it in a console without arguments, you will see | ||
+ | something that resembles this: | ||
- | This will cause emacs to load the specified file when it starts up, skipping the welcome message. | + | |
+ | [[emacs-startup.png|Starting Out]] | ||
- | **Command Keys** | + | If you are in X windows, |
+ | start a GUI instead of running in your console. | ||
+ | case and you don't want a GUI, you can invoke it with the flag | ||
+ | //' | ||
- | As mentioned above, emacs uses **CTRL** and **ALT** combinations for commands. The usual convention is to write these with **C**-letter and **M**-letter, | ||
- | <note> | + | While here, you can browse around using the |
- | </note> | + | keyboard arrow keys. |
+ | Underlined elements are links, and you can activate them by | ||
+ | moving over them and pressing | ||
+ | mentioned | ||
+ | should you have any problems. | ||
+ | sequences such as < | ||
+ | < | ||
+ | key while holding down the < | ||
+ | with **M-`**, meaning to hold the the | ||
+ | **Meta** key (usually < | ||
+ | press the backtick < | ||
+ | the < | ||
+ | holding down the < | ||
+ | is also one of the more important commands in | ||
+ | **// | ||
- | Many emacs commands consist of sequences of keys and key combinations. For example, **C**-x **C**-c (that is **CTRL**-x followed by **CTRL**-c) quits Emacs, **C**-x **C**-s saves the current file. Keep in mind that **C**-x **C**-b is not the same as **C**-x b. The former means **CTRL**-x followed by **CTRL**-b, while the latter means **CTRL**-x followed by just ' | ||
- | ===== Buffers ===== | + | Alternatively, |
+ | file name as an argument, it will open that file, just like | ||
+ | **// | ||
+ | presented with the contents of the file in question. | ||
+ | navigate the document using traditional arrow keys and type in | ||
+ | information at will without any issues. | ||
- | In emacs, the concept of ' | ||
- | There is one other special buffer | + | Say you make some edits, and you now want to save your file. |
+ | The following key sequence will do that: < | ||
+ | If you made a new file, you will be prompted for this in what is | ||
+ | called | ||
+ | the bottom of the screen. Type in the file name of your choice, | ||
+ | then hit < | ||
+ | save the file, you can press < | ||
+ | operations that ask for input. | ||
+ | usually available for operations that use the minibuffer. | ||
- | Switching from one buffer to another can be done with the command C-x b. This will prompt you for the name of a buffer (a buffer' | ||
- | If you want to switch to another buffer than the default offered by Emacs, | + | Should |
+ | **//Emacs//** session, type in < | ||
+ | minibuffer. | ||
+ | whether it exists or not. If it doesn' | ||
+ | will be created for it (the file will be created upon saving | ||
+ | with < | ||
+ | expected. | ||
+ | switch back to it using < | ||
+ | the file's name (or more technically, | ||
+ | hitting < | ||
+ | ===== How to Move Around ===== | ||
- | You can get a list of open buffers by hitting C-x C-b. This command will usually split the screen in two, displaying the buffer you were working in in the top half, and a new buffer called | + | Like **//vi//**, |
+ | **//Emacs//** is also older than the arrow | ||
+ | keys on your keyboard. Also, like in | ||
+ | **//vi//**, using the arrow keys to navigate | ||
+ | files is also supported. | ||
+ | **//vi//** movement keys are more ergonomic, | ||
+ | **// | ||
+ | However, | ||
+ | **// | ||
+ | efficiently. Here is a table of the basic movement keybindings: | ||
- | ===== Modes ===== | + | |
+ | **Emacs Cursor Movement** | ||
+ | ^Command^Result| | ||
+ | |< | ||
+ | |< | ||
+ | |< | ||
+ | |< | ||
+ | Of course, like with **//vi//** it is also | ||
+ | possible to repeat these commands with a numeric argument. | ||
+ | type in **M-1** **M-0** < | ||
+ | < | ||
+ | **M-5** < | ||
+ | will move five characters to the right. | ||
+ | ===== Getting Help ===== | ||
- | Every buffer in emacs has an associated mode. This mode is very different from the idea of modes in vi: a mode tells you what kind of buffer you are in. For example, there is text-mode for normal text files, but there are also modes such as c-mode for editing C programs, sh-mode for editing shell scripts, latex-mode for editing LaTeX files, mail-mode for editing email and news messages, etc. A mode provides | + | **// |
+ | documentation, to the point that it is often called a | ||
+ | //" | ||
+ | mechanisms | ||
+ | using it. | ||
- | The modes mentioned above are called //major// modes. Each buffer has exactly one major mode. Additionally, | + | Here are some useful functions |
+ | all start with <key>C-h</ | ||
- | ==== Opening Files ==== | ||
- | To open a file in emacs, type C-x C-f | + | **Accessing Emacs Documentation** |
+ | ^Command^Result| | ||
+ | |< | ||
+ | |< | ||
+ | |< | ||
+ | |< | ||
- | Emacs will ask you for the name of the file, filling in some default path for you (which is usually ~/ ). After you type the filename (you can use Tab completion) and hit ENTER, emacs will open the file in a new buffer and display that buffer on the screen. | + | |
+ | < | ||
+ | ===== Calling Functions ===== | ||
- | < | + | As noted earlier, **//Emacs//** exports |
+ | large number of functions to for interactive use. Some of | ||
+ | these, like those opening and saving files, are mapped to keys. | ||
+ | Others (like the ones for moving to the beginning and end of | ||
+ | lines) are not. To call them, you have to invoke them. Say we | ||
+ | want to call the function | ||
+ | this: | ||
- | In order to create a new file in emacs, you cannot just go typing right away. You first have to create a buffer for it, and come up with a filename. You do this by typing C-x C-f and typing a filename, just as if you were opening an existing file. Emacs will notice that the file you typed doesn' | ||
- | When you type C-x C-f and then enter a directory name instead | + | **M-x** end-of-line < |
- | < | ||
- | When you have typed C-x C-f and suddenly change your mind, you can type C-g to cancel | + | And the cursor would move to the end of the line, as the function name |
+ | suggests. | ||
+ | ===== Emacs Cheat Sheet ===== | ||
- | ===== Basic Editing ===== | + | While Emacs can be simple to use, its scope can easily be |
+ | overwhelming. | ||
+ | aspects have been simplified, most notably regarding text | ||
+ | selection. | ||
+ | **// | ||
+ | tutorials. | ||
+ | searches. | ||
- | When you have opened a file, you can of course move around in it with the cursor. The cursor keys and **PgUp**, **PgDn** do what you'd expect. **Home** and **End** jump to the beginning and end of the line. (In older versions, they would actually jump to the beginning and end of the buffer.) However, there are also **CTRL** and Meta (**ALT**) key combos that move the cursor around. Because you do not need to move your hands to another part of the keyboard for these, they are much quicker once you get used to them. | ||
- | Basic emacs Editing Commands | + | **Emacs Cheat Sheet** |
- | ^ Command ^ Result | + | ^Command^Result| |
- | |C-b|go one character | + | |<key>C-f</ |
- | |C-f|go one character | + | |<key>C-b</ |
- | |C-n|go one line down| | + | |<key>C-n</ |
- | |C-p|go one line up| | + | |<key>C-p</ |
- | |C-a|go to the beginning of the line| | + | |<key>C-h</ |
- | |C-e|go to the end of the line| | + | |<key>C-h</ |
- | |M-b|go one word back| | + | |< |
- | |M-f|go one word forward| | + | |< |
- | |M-}|go one paragraph forward| | + | |M-< |
- | |M-{|go one paragraph backward| | + | |< |
- | |M-a|go one sentence backward| | + | |M-< |
- | |M-e|go one sentence forward| | + | |M-< |
- | |C-d|delete the character under the cursor| | + | |<key>C-u</ |
- | |M-d|delete until the end of the current | + | |M-< |
- | |C-v|go down one screen (i.e., **PgDn**)| | + | |M-< |
- | |M-v|go up one screen (i.e., **PgUp**)| | + | |M-< |
- | |M-<|go to the beginning of the buffer| | + | |M-<key>'<'</ |
- | |M->|go to the end of the buffer| | + | |< |
- | |C-_|undo the last change | + | |<key>C-space</ |
- | |C-k|delete | + | |<key>C-w</ |
- | |C-s|forward | + | |M-< |
- | |C-r|reverse | + | |C-< |
+ | |< | ||
+ | |< | ||
+ | |< | ||
+ | |<key>C-r</ | ||
+ | |M-< | ||
+ | |< | ||
+ | |< | ||
+ | |< | ||
- | Note that many Meta commands are parallel to the **CTRL** commands except that they operate on larger units: while C-f goes forward one character, **M**-f goes forward an entire word, etc. | + | ====== Chapter Navigation ====== |
- | Also note that **M**-< and **M**-> require you to type **SHIFT**+**ALT**+comma and **SHIFT**+**ALT**+dot respectively, | + | **Previous Chapter: [[slackbook: |
- | Note that C-k deletes (kills, as it is commonly called) all the text after the cursor to the end of the line, but doesn' | + | **Next Chapter: [[slackbook: |
- | + | ====== Sources ====== | |
- | ===== Saving Files ===== | + | <!-- If you copy information |
- | + | * Original source: [[http:// | |
- | In order to save a file, you type **C**-x **C**-s | + | <!-- Authors |
- | + | * Originally written | |
- | Emacs will not ask you for a filename, the buffer will just be saved to the file it was loaded | + | <!-- * Contrbutions by [[wiki: |
- | + | ||
- | When you save the file for the first time in this session, emacs will normally save the old version of your file to a backup file, which has the same name appended with a tilde: so if you're editing a file cars.txt, emacs will create a backup cars.txt~. | + | |
- | + | ||
- | This backup file is a copy of the file that you opened. While you are working, emacs will also regularly create an auto-save copy of the work you are doing, | + | |
- | + | ||
- | When you are done editing a file, you can kill the buffer that holds it by typing C-x k | + | |
- | + | ||
- | Emacs will then ask you which buffer you want to kill, with the current buffer as default, which you can select by hitting **ENTER**. If you haven' | + | |
- | + | ||
- | If you'd prefer to save the file with a new name so that you don't overwrite the original version, use **C**-x **C**-w instead. You may then give a new name for the file, and the buffer will be updated to reflect the contents of this new file, leaving the old file unchanged. | + | |
- | + | ||
- | ===== Quitting Emacs ===== | + | |
- | + | ||
- | When you are done with emacs altogether, you can type **C**-x **C**-c | + | |
- | + | ||
- | This quits emacs. If you have any unsaved files, emacs will tell you so, and ask if you want to save them each in turn. If you answer no to any of these, emacs will ask for one final confirmation and then quit. | + | |
+ | <!-- Please do not modify anything below, except adding new tags.--> | ||
+ | <!-- You must also remove the tag-word " | ||
+ | {{tag> |