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 emacs26Then 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.
Cstand for ControlM(meta) stands for AltSfor Shiftsfor 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-nmove down a lineC-pmove up a lineC-fmove forward a characterC-bmove backward a characterC-x C-ffind file and openC-x ddired or show directoryC-x bswitch buffer in minibufferC-x C-bshow buffersC-x C-cexit emacsC-x C-ssave fileM-xexecute command
C-h kdescribe key pressedC-h cdescribe key brieflyC-h fdescribe function nameC-h vdescribe variable nameC-h mdescribe 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-xswitches toC-c, so to send an actualC-cto the terminal type it twice, i.e.C-c C-c. - In
term-mode, commandC-c C-jswitches toterm-line-modeand you can navigate text with regular key-binds; commandC-c C-kswitches toterm-char-modewhich behaves like terminal emulator. - In order to send escaped characters to
term, switch toterm-line-modewithC-c C-jthen inserted quoted characterC-q C-xand switch back toterm-char-mode. So now,C-xis sent to the terminal emulator.
Shell mode commands
M-n(orC-<up>) andM-p(orC-<down>) to cycle next and previous commandsC-aandC-ego to beggining and end of lineM-x send-invisibleto hide typed textM-r(comint-history-isearch-backward-regexp; similar to regularC-rin terminal emulators) search from previous commands- After
M-r, cycle matches withC-rbackward orC-sforward in history
- After
C-c M-r(comint-previous-matching-input-from-input) search backwards using current prompt stringC-c C-lcreate 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
dmark for deletionxdelete alld-marked files and foldersmmark for copy, moveuunmark file or folderUunmark allCcopy a file and prompt for new file nameRrename a file or folder+create folderZcompress files usinggzip; note the old file is renamed to*.gzgrevert 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-bufferto refresh the contents of current buffer from hard storageauto-revert-modeminor mode for automatically reverting a bufferauto-revert-tail-modeminor 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