¡Esta es una revisión vieja del documento!
Tabla de Contenidos
Emacs
¿Qué es Emacs?
vi y sus clones son editores muy funcionales y poderosos. Sin embargo, a menudo no se consideran particularmente extensibles. vim es un sucesor exitoso y poderoso de vi que contradicen esta tendencia, siendo a la vez extremadamente extensible y ligero. Sin embargo, muchos usuarios prefieren un editor más “pesado” y extensible. Esta es la razón por la que muchas personas (incluido el autor de este capítulo) prefieren Emacs.
Emacs eleva la extensibilidad a la enésima potencia. Aparte de un núcleo de C, el resto de Emacs/ está escrito en un variante de Lisp, casi toda la cual es accesible, de modo que usted puede configurarlo o incluso extenderlo a voluntad (muchos buenos tutoriales de Emacs Lisp se pueden encontrar en Internet). La gente ha escrito todo tipo de extensiones en Emacs Lisp, desde el resaltado de sintaxis para un oscuro lenguaje, a un terminal incorporado. De hecho, hay incluso un modo de emulación vi dentro de Emacs (llamado viper), así que usted todavía puede obtener el modo de edición que viene con vi, mientras que dispone de toda la potencia del núcleo de Emacs.
Como con vi, hay muchas variantes de Emacs/ (llamadas “emacsen”). Sin embargo, el más usado (y el único en Slackware) es el Emacs de GNU. Cuando la gente hace referencia a “Emacs” directamente, casi siempre se refieren el Emacs de GNU.
A diferencia de vi, Emacs Opera más bien como un editor tradicional por defecto. Esto significa que la mayoría de los accesos directos del teclado se pueden realizar sin tener que cambiar de modo repetidamente. Puedes abrir un archivo y empezar a escribir sin tener que aprender lo que hacen los modos, u olvidarte de cuál de ellos estás usando actualmente.
Iniciando
Emacs se puede iniciar simplemente ejecutando el comando emacs en la terminal. Cuando se inicia por primera vez en una consola sin argumentos, se ve algo parecido a esto:
Si está en las ventanas X, Emacs puede iniciar una GUI en vez de ejecutarse en la consola. Si este es el caso y no desea una GUI, puede invocarlo con la opción '-nw'.
Una vez aquí, puede moverse usando las teclas de dirección. Los elementos subrayados son enlaces, y se pueden activar moviéndose encima y pulsanso Intro. La documentación mencionada es muy buena, y puede ayudarle a orientarse si tiene algún problema. Advierta también cómo se describen las secuencias de teclas como Ctrl+H, significando pulsar la tecla h mientras se aprieta la tecla CTRL. Ocurre lo mismo con M-`, que significa mantener pulsada la tecla Meta (normalmente Alt) y pulsar la tecla del acento reverso `. Cuando se dice por ejemplo Ctrl+X Ctrl+C, significa pulsar la tecla x mientras se mantiene apretada la tecla CTRL, y entonces pulsar la tecla c mientras también se mantiene apretada la tecla CTRL. Convenientemente, este es también uno de los comandos más importantes en Emacs: cerrarlo.
Alternativamente, si llama a emacs/ con un nombre de archivo como argumento, abrirá ese archivo, igual que vi. Al hacer esto, se le presentará el contenido del archivo en cuestión. Aquí, usted puede navegar por el documento con las teclas de flecha tradicionales y teclear información a voluntad sin ningún problema.
Digamos que hace algunas modificaciones y ahora quiere guardar el archivo. La siguiente secuencia de teclas lo hará: Ctrl+XCtrl+S. Si ha creado un nuevo archivo, se le pedirá que lo haga en lo que se denomina “minibuffer”, la línea en blanco debajo de la línea gris en la parte inferior de la pantalla. Escriba el nombre del archivo de su elección, luego presione Enter. Si no quiere guardar el archivo, puede presionar Ctrl+G, que abortará las operaciones pendientes de entrada de datos. Tenga en cuenta que la compleción de nombres por la tecla tab está normalmente disponible para las operaciones que utilizan el minibuffer.
Si desea abrir un archivo nuevo dentro de su sesión actual de Emacs, teclee Ctrl+XCtrl+F. Se le pedirá un nombre de archivo en el minibuffer. Emacs no se preocupa de si existe o no. Si no existe, se creará un nuevo buffer para él (el archivo se creará cuando se guarde con Ctrl+XCtrl+S), o se abrirá como se espera. Sin embargo, ¡el archivo antiguo estará abierto aún! puede volver a él usando Ctrl+XCtrl+B, entrando en el nombre del archivo (o, más técnicamente, el nombre del buffer), y entonces pulsando Intro.
Cómo Moverse
Como vi, Emacs también es más antiguo que las flechas. en el teclado. Además, como en vi, usar las teclas de flechas para navegar también es compatible. Mientras que las teclas de movimiento vi son más ergonómicas, las de Emacs son más bien “mnemotécnicas”. Sin embargo, aún así es muy posible operar con los atajos de teclado principales de /Emacs rápida y eficientemente. Aquí hay una tabla con los principales atajos de teclado para el movimiento:
El Movimiento del cursor de Emacs
Comando | Resultado |
---|---|
Ctrl+F | Mueve el cursor un carácter a la derecha (forward) |
Ctrl+B | Mueve el cursor un carácter a la izquierda (backward) |
Ctrl+N | Mueve el cursor una línea abajo (next) |
Ctrl+P | Mueve el cursor una línea arriba (previous) |
Por supuesto, al igual que con vi es posible repetir estos comandos con un argumento numérico. Si teclea M-1 M-0 Ctrl+P, o Ctrl+U 10 Ctrl+P, el cursor se moverá diez líneas arriba. Si teclea M-5 Ctrl+F o Ctrl+U 5 Ctrl+F, el cursor se moverá cinco caracteres a la derecha.
Consiguiendo ayuda
Emacs contiene una gran cantidad de documentación, hasta el punto de que a menudo se le llama el editor “auto-documentado”. Esto se debe a que proporciona mecanismos para proporcionar a los usuarios documentación mientras están usándolo.
Here are some useful functions that display documentation (they all start with Ctrl+H):
He aquí algunas funciones útiles que muestran documentación (todas empiezan con Ctrl+H):
Accediendo a la Documentación de Emacs
Comando | Resultado |
---|---|
Ctrl+H f NOMBRE-FUNCIÓN Intro | Muestra la documentación para la función NOMBRE-FUNCIÓN |
Ctrl+H k Ctrl+X Ctrl+C | Muestra la documentación para la función enlazada con las teclas Ctrl+X Ctrl+C |
Ctrl+H t | Muestra el tutorial de Emacs |
Ctrl+H ? | Muestra todas las funciones relacionadas con la ayuda |
Ctrl+H t es especialmente útil si necesitas ayuda o práctica con Emacs.
Calling Functions
As noted earlier, Emacs exports a 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 “end-of-line”. We would do this:
M-x end-of-line Enter
And the cursor would move to the end of the line, as the function name suggests.
Emacs Cheat Sheet
While Emacs can be simple to use, its scope can easily be overwhelming. Below are some useful Emacs commands. Some aspects have been simplified, most notably regarding text selection. These concepts, and more, are described the Emacs manual, and various on-line tutorials. Decent summaries can also be gleaned from web searches.
Emacs Cheat Sheet
Command | Result |
---|---|
Ctrl+F | Move the cursor one character to the right (forward) |
Ctrl+B | Move the cursor one character to the left (backward) |
Ctrl+N | Move the cursor one line down (next) |
Ctrl+P | Move the cursor one line up (previous) |
Ctrl+H f FUNCTION-NAME Enter | Show documentation for function FUNCTION-NAME |
Ctrl+H k Ctrl+X Ctrl+C | Show documentation for the function bound to the keys Ctrl+X Ctrl+C |
Ctrl+H T | Show the Emacs tutorial |
Ctrl+H ? | Show all help-related functions |
M-` | Access the Menu Bar |
Ctrl+G | Cancel the current operation. This is most useful when in the minibuffer. |
M-X FUNCTION-NAME Enter | Call the interactive function FUNCTION-NAME |
M-1 M-0 Ctrl+N | Move the cursor ten lines down |
Ctrl+U 10 Ctrl+N | Move the cursor ten lines down (same as above) |
M-x beginning-of-line | Move the cursor to the beginning of the current line |
M-x end-of-line | Move the cursor to the end of the current line |
M-> | Move the cursor to the end of the buffer |
M-< | Move the cursor to the beginning of the buffer |
Ctrl+K | Remove text from the cursor to the end of the line and place it into the kill ring |
Ctrl+Space | Enter selection mode (use normal motion keys to move around). Press C-space again to leave it. |
Ctrl+W | While in selection mode, delete the selected region, and store the result into the kill ring |
M-W | While in selection mode, store the selected region into the kill ring. |
C-Y | “Yanks” the contents of the kill ring and places them at the cursor's location |
Ctrl+/ | Undo the previous action. Unlike most other editors, this includes previous undo actions. |
Insert | Enable or disable overwriting characters |
Ctrl+S asdf Enter | Forward incremental search for the string “asdf”. Repeat Ctrl+S as needed to search for future items, or Ctrl+R (below) to search backwards. |
Ctrl+R asdf Enter | Backward incremental search for the string “asdf”. Repeat Ctrl+R as needed to search for future items, or Ctrl+S (above) to search forwards. |
M-% old Enter new Enter | Search for each instance of “old” and prompt you to replace it with “new”. You can force replacement of all items by typing ! at the replacement prompt. |
Ctrl+X Ctrl+C | Exit Emacs, prompting you to save each unsaved buffer before doing so |
Ctrl+X Ctrl+S | Save the currrent buffer to its file |
Ctrl+X Ctrl+W new-file.txt Enter | Save the current buffer to a file “new-file.txt” |
Chapter Navigation
Previous Chapter: vi
Next Chapter: Networking
Sources
- Original source: http://www.slackbook.org/beta
- Originally written by Alan Hicks, Chris Lumens, David Cantrell, Logan Johnson