Skip to content

Instantly share code, notes, and snippets.

@KeyC0de
Created November 22, 2020 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeyC0de/dd6f6e770e918e028d17ff6fe6c948ba to your computer and use it in GitHub Desktop.
Save KeyC0de/dd6f6e770e918e028d17ff6fe6c948ba to your computer and use it in GitHub Desktop.
Nikos Lazaridis (KeyC0de) - https://github.com/KeyC0de
Emacs Tutorial
General:
-----------------
F10 : Enter Menu options
F11 : Fullscreen mode
[C stands for CTRL, M stands for ALT / COMMAND]
File Handling:
--------------
C-x C-f : Opens a file, asks for the file name. If it cannot find the file, creates the file
C-x C-s : Saves the file without a prompt
C-x C-s : Saves all files with a prompt
C-x C-w : Saves the file with a different name. Asks you for the name.
Everytime you save a file, Emacs creates another file with the name "filename~".
This tilde(~) file is the previous version of the file. It will be in the same dir.
Also, Emacs auto-saves everything you type to a file with the name "#filename#".
If you quit Emacs without saving, you can see this auto-save file. Let's do that.
C-x C-c : Quits Emacs.
M-x recover-file: recovers the auto-saved file.
Copy/Cut/Paste:
------------------------
C-k : Kills / deletes the whole line, puts it into the clipboard
C-y : Pastes whatever is in the clipboard at the cursor.
Subsequent C-y's will keep on pasting
C-space : Start highlighting / marking a region
M-w : Copies this region into the clipboard
C-w : Cuts this region into the clipboard
Cursor Commands / Navigation:
-----------------------------
C-a : Beginning of line
C-e : End of the line
C-/ : Undo
C-g C-/ : Redo
M-> : End of buffer (M stands for ALT / COMMAND button)
M-< : Beginning of buffer
Buffer Management Commands:
---------------------------
C-x b : Switches buffers, asks you which buffer to switch to
C-x C-b : Switches buffers, but shows you the list of buffers in a new window
Hit C-x o (other window) to go to the other window and hit <enter> on the buffer you want to switch to
C-x 0 : Will close that window
C-x 1 : Will leave only one window
C-x 2 : WIll make a horizontal cut and show a secondary window
Searching:
----------------
C-s : searches forward as you type. Beware \n is not newline, it is C-j.
C-s will also find the next occurence
C-g : quits the search
M-C-s : searches a regexp (C-s & C-g to navigate as usual)
Commands:
---------
Emacs understands elisp. It is a dialect of Lisp
M-x commandName : Will execute the command.
M-x pwd : Prints working directory
M-x indent-region : Indents code highlighted
C-g : leaves the command interface
~/.emacs file and Packages:
---------------------------
Emacs is very versatile, you can program it, add new abilities to it. Let's say that
we develop a new language that Emacs does not know about. All we have to do is to
write a "package" so that Emacs can color-code it for instance. Or even write a package
for Emacs to auto complete keywords in this language. This makes Emacs a platform for
editing many different things
~/.emacs file (A file called ".emacs" under your home directory) holds all the elisp
statements that is run when you start your Emacs.
~/.emacs.d directory (A directory called ".emacs.d" under your home directory) holds
all the packages (files of lisp commands / statements) for Emacs.
You load a package by refering it in a "require" statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment