Download Emacs tarball from https://ftp.gnu.org/gnu/emacs/
Extract with
tar zxvf emacs-<version>.tar.gz
Set up install location, the default is /usr/local/
./configure --prefix=/usr/local
Then install with
make && make install
sudo add-apt-repository ppa:kelleyk/emacs
sudo apt-get update
sudo apt install emacs26
Then delete the repository from /etc/apt/sources.list.d
, if you do not trust it.
Gnutls not found
apt-cache search libgnutls.*-dev
apt-get install libgnutls.<version>-dev
In case your Emacs icon is missing
sudo gtk-update-icon-cache /usr/share/icons/hicolor
After installing brew
,
brew install --cask emacs
Go to Finder > Applications
, then right-click Open
. Otherwise, you get Apple can't check app for malicious software
If you get the error Opening directory: Operation not permitted, /Users/nalma/Documents/
, then give permission to ruby
which launches the Emacs.
Emacs looks for an init file ~/.emacs
, ~/.emacs.el
and ~/.emacs.d/init.el
in that order.
vi
is archaic version of Vim. With Vim you usually edit files and go back to terminal but with Emacs you try to do everything inside it.
There is a compromise called evil-mode
which let's you use Vim keybinding.
Mnemonics - makes sense but kinda horrible
For example, the combination C-n
(hold Control and press n) moves cursor to the next line and C-p
to the previous line.
C
stand for ControlM
(meta) stands for AltS
for Shifts
for Super or windows
e.g. C-n
, C-x C-f
, <return>
, RET
, etc.
You can also have combinations such as C-M-x
(hold Control and Alt, then press x).
Note that Emacs will try to map shifted keys to regular keys if they are not bound, so for example M-x
and M-X
map to the same thing, i.e. execute-extended-command
.
C-x C-f
is two combinations is sequence, so press C-x
first (you will see it minibuffer as C-x-
) and then press C-f
.
DO NOT try to hold Control while trying to press x
and f
in sequence because it puts too much strain on your fingers and can result in RSI (Repetitive-Strain-Injury) Syndrom. Or even better is to remap frequent keys into dedicated keys or use fewer key strokes.
cheat sheet at https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
C-n
move down a lineC-p
move up a lineC-f
move forward a characterC-b
move backward a characterC-x C-f
find file and openC-x d
dired or show directoryC-x b
switch buffer in minibufferC-x C-b
show buffersC-x C-c
exit emacsC-x C-s
save fileM-x
execute command
C-h k
describe key pressedC-h c
describe key brieflyC-h f
describe function nameC-h v
describe variable nameC-h m
describe current modes used
Modes to help
(which-key)
show commands for a prefix after a delay
Type either shell
for dumb terminal or term
which behaves same as regular terminal
Note:
- inside
term
, the prefix commandC-x
switches toC-c
, so to send an actualC-c
to the terminal type it twice, i.e.C-c C-c
. - In
term-mode
, commandC-c C-j
switches toterm-line-mode
and you can navigate text with regular key-binds; commandC-c C-k
switches toterm-char-mode
which behaves like terminal emulator. - In order to send escaped characters to
term
, switch toterm-line-mode
withC-c C-j
then inserted quoted characterC-q C-x
and switch back toterm-char-mode
. So now,C-x
is sent to the terminal emulator.
Shell mode commands
M-n
(orC-<up>
) andM-p
(orC-<down>
) to cycle next and previous commandsC-a
andC-e
go to beggining and end of lineM-x send-invisible
to hide typed textM-r
(comint-history-isearch-backward-regexp
; similar to regularC-r
in terminal emulators) search from previous commands- After
M-r
, cycle matches withC-r
backward orC-s
forward in history
- After
C-c M-r
(comint-previous-matching-input-from-input
) search backwards using current prompt stringC-c C-l
create buffer with command per line
Often it is useful to reexecute several successive shell commands that were previously executed in sequence. To do this, first find and reexecute the first command of the sequence. Then type
C-c C-x
; that will fetch the following command—the one that follows the command you just repeated. Then type<RET>
to reexecute this command. You can reexecute several successive commands by typingC-c C-x <RET>
over and over.
source: https://www.gnu.org/software/emacs/manual/html_node/emacs/Shell-Ring.html
Anywhere in Emacs
M-!
to execute single shell commandC-u M-!
same asM-!
but insert command output at the mark point
Usually C-w
, M-w
and C-y
are used for cutting, copying and pasting. Inside a terminal use S-<insert>
and C-<inseart>
for copying and pasting; the mark can be set with C-<space>
albeit being invisible.
Type C-x d
to open dired
d
mark for deletionx
delete alld
-marked files and foldersm
mark for copy, moveu
unmark file or folderU
unmark allC
copy a file and prompt for new file nameR
rename a file or folder+
create folderZ
compress files usinggzip
; note the old file is renamed to*.gz
g
revert buffer<
previous directory in a current dired buffer>
next directory in dired buffer^
go to parent directory
Open find-file
by pressing C-x C-f
UseC-x C-f /sudo:user@localhost:
, this is similar to sudo -s
function.
To mimic su
issue command and type C-x C-f /su:root@localhost:/
; localhost is synonymous with hostname.
Syntax /<method>:<user>@<host>:<dir>
.
For Linux-based systems, /ssh:user@host:/
On MS Windows, use PuTTY's plink
method, /plink:user@host:/path/to/file
Incase you need to change user inside remote host then issue C-x C-f /ssh:userA@remoteA|ssh:userB@remoteA:/
. The same method can be used to hop from a remote host to another remote host.
default-directory
variable dictaces where shell is opened. The following function will prompt for SSH string, e.g. "/ssh:user@host:/".
(defun remote-shell (remote-string)
(interactive "sRemote:")
(let ((default-directory remote-string))
(shell remote-string)))
# ~/.ssh/config
Host goo
HostName google.ca
User root
Then type C-x C-f /ssh:goo:/
to get password prompt
Type M-x
and then
revert-buffer
to refresh the contents of current buffer from hard storageauto-revert-mode
minor mode for automatically reverting a bufferauto-revert-tail-mode
minor mode for reverting and moving point to end of file
M-x align-regexp
to align columns based on a regex separator
To type unicode characters, the toggle custom input C-\
and type \lambda
to get λ
.
To find how a unicode can be inserted, hover over it and type C-u C-x =
.
(add-to-list
'directory-abbrev-alist
'("^/jou" . "~/mnt/mdbackup/journal" ))
Then type C-x C-f /jou <RET>
C-x r m
mark for bookmark
C-x r b
prompt for saved bookmarks
cs:ch-fr buffer pos line (major minor)
cs
describes character set
ch
--
unmodified both locally and on disk**
buffer is modified%*
READ-ONLY file changed on disk%%
READ-ONLY file not changed
List is '(a f b)
, without '
an apostrophe the first atom (indivisible unit in elisp) is treated as a function.
Universal across many applications. Having ease access of modifier keys is important.
if your package expires either disable signature checking
(setq package-check-signature nil)
or install it manually
gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40
source: http://elpa.gnu.org/packages/gnu-elpa-keyring-update.html