reddit / emacs

Wrote some basic emacs notes for myself as I kept forgetting these and looking these up would take a lot of time in the dense manuals.

LowCom · 2022-05-05 03:42
kalyan &#x200B; &#x200B; Table of Contents ───────────────── &#x200B; 1. Emacs guide. .. 1. Some basic key notes. .. 2. Config file .. 3. Some key concepts .. 4. Shells .. 5. File browser .. 6. Window management .. 7. Help .. 8. Evil mode .. 9. Org mode ..... 1. Headings and formatting and paragraphs and lists ..... 2. Date and time ..... 3. Tables ..... 4. Timers .. 10. Exporting &#x200B; &#x200B; 1 Emacs guide. ══════════════ &#x200B; 1.1 Some basic key notes. ───────────────────────── &#x200B; The key binds below should be enough for basic editing of files. C-x means control plus x while M-x means Alt plus x. M-x runs any command or function that can modify the present emacs buffer. C-x C-c closes emacs. C-x C-s saves the file. C-x C-f opens a file specified for editing, creates new one if such a file doesn't exist. C-b opens a buffer with buffer name, creates new one if such a buffer doesn't exist. C-a, C-e for beggining and end of a line. M-<, M-> for beggining and end of the buffer. C-SPC to set a mark. C-w to kill from mark to present point, M-w to copy instead.(killing means cutting, deleting means cut text is not available for pasting) C-y to yank the killed or copied contents.(yank means to paste) C-/ or C-x u to \*undo\*. C-k to kill a line. &#x200B; &#x200B; 1.2 Config file ─────────────── &#x200B; It is located in either \~/.emacs or \~/.emacs.d/init.el It can contain variables and functions which will be loaded at startup. &#x200B; &#x200B; 1.3 Some key concepts ───────────────────── &#x200B; 1. Buffer is not same as file, it will saved to file once closed. It is an editing area in RAM, need not be associated with any file. 2. There are many buffers which are not stored to files like calculator, tetris, diary,etc. 3. Scratch buffer is not saved gives a rough area to work on. 4. Windows are the split areas on the screen, they contain buffers. 5. A frame in Emacs is what we call usually a window. Closing the frame will close all [buffers.You](https://buffers.You) can have multiple frames and navigate between them. &#x200B; &#x200B; 1.4 Shells ────────── &#x200B; • M-x eshell gives access to emacs shell which can run shell commands and also lisp. • term also launches a shell. • ielp is the lisp REPL. • M-& runs the shell command you enter in a separate buffer called async. • M-x runs any interactive function on the current buffer, for eg. forward-char moves the cursor to the next letter. (It is bound to ":" in evil). • M-: runs any lisp code, it need not be an interactive function like with M-x. &#x200B; &#x200B; 1.5 File browser ──────────────── &#x200B; • Dired is the builtin file browser accessed through C-x d. • With this you can open, rename and delete files. • Type a path after opening dired, • f opens the file at the cursor • g does ls on the directory at the cursor. &#x200B; &#x200B; 1.6 Window management ───────────────────── &#x200B; • C-x 0 closes current window. • C-x 1 closes all windows except the current one. &#x200B; &#x200B; 1.7 Help ──────── &#x200B; • C-h k opens help for a key combo you specify. • Similarly f is for function, m is for mode. • t opens tutorial, • h opens manual, i opens all manuals (not just for emacs) &#x200B; &#x200B; 1.8 Evil mode ───────────── &#x200B; • Enter and exit evil mode through C-z • Run commands through ":", equivalent of M-x. • You can use vim window and buffer movement keys like :bn, :bp, C-ww, C-wq etc. &#x200B; &#x200B; 1.9 Org mode ──────────── &#x200B; Only the most basic and useful commands are listed below. Refer to org manual for more details. <[https://orgmode.org/manual/index.html#SEC\_Contents](https://orgmode.org/manual/index.html#SEC_Contents)\> &#x200B; &#x200B; 1.9.1 Headings and formatting and paragraphs and lists ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ &#x200B; Headings use \* instead of # used in markdown. M-RET inserts a new heading below current one. (This applies to lists, sub-headings and all elements) Formatting: \*bold\*, /italic/, \_underline\_. \\\\ at the end of a line causes a linebreak. Or else use, #+BEGIN\_VERSE and END\_VERSE to retain line breaks and indents within a block of text. Bullted lists beging with - and numbered ones with numbers. You can use the M-RET trick for lists too. M-Up and down arrow keys will move list elements up and down. The same can be done with headings and subheadings. Introducing a list element in the middle will auto readjust the numbers. &#x200B; &#x200B; 1.9.2 Date and time ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ &#x200B; C-c ! will insert an inactive date. (. instead of ! inserts an active date) &#x200B; &#x200B; 1.9.3 Tables ╌╌╌╌╌╌╌╌╌╌╌╌ &#x200B; Create a new table with | and enter fields separated by pipes. Typing tab or return will autocomplete table skeleteon and readjust table alignment. For the second row, type | and — and then press tab to autocomplete table. To navigate, use tab and enter. Shift + tab/enter will reverse the movement. To adjust the display length of field, add a row on top below header with value like <10>. This will show field upto size 10. C-c | on a csv will make a table, while the same key combo will create a new table with ability to specify rows and columns. It will create an empty table if region doesn't contain anything. &#x200B; &#x200B; ◊ [1.9.3.1](https://1.9.3.1) Formulas &#x200B; = will start formula in a field. You can use excel like notation like =A1+B2. Or proper notation is u/2$3 which means row 2 and column 3, this is absolute reference. u/-2$+3 means 2 rows above and 3 columns right, this is relative reference. u/0 and $0 refer to current row and column, if ommited it's understood be self. Column formula: $4 = $3 + $2 will fill all columns of column 4. Initially only one field is filled, but go to the formula bar auto typed below and then press C-c C-c on it, it will autoupdate all the formulas. C-c + will show the sum of all rows above in the minibuffer, S-Insert will insert this value into the current field. &#x200B; &#x200B; 1.9.4 Timers ╌╌╌╌╌╌╌╌╌╌╌╌ &#x200B; These start a stopwatch C-c C-x 0 (org-timer-start) C-c C-x , (org-timer-pause-or-continue) C-c C-x \_ (org-timer-stop) The one below starts a countdown timers. C-c C-x ; (org-timer-set-timer) &#x200B; &#x200B; 1.10 Exporting ────────────── &#x200B; C-c C-e will open export menu and then options there are self explanatory. Export to markdown or html requires you to use linebreaks either with \\\\ or BEGIN\_VERSE.
dpoggio · 2022-05-05 04:09
You can use `which-key-mode` if you are learning and want a helping cheat sheet while typing. Also, I often don’t remember a key chord but I remember some of the concept; `helm-M-x` speeds me up. `C-u C-c C-c` on the table is easier than `C-c C-c` on the formula. You can insert date-time ranges just using `C-c .` and it’s inactive partner twice without moving the point. You can switch to/from inactive from/to active with Shift-up or down on the `<` or `[`. You can ask me for more tips. Now I’m sleepy.
centuryx476 · 2022-05-05 04:16
Thank You. I'm still learning the basics
bhrgunatha · 2022-05-05 05:34
It seems weird but I often forget about tweaks that I've made or key bindings I've added or changed, so I made an anki deck for myself. Now when I start using a new package or learn a trick or a feature that's new to me, I add it to my deck to help me remember. For example I only recently started using avy. Since I always use C-0 ... C-9 for numeric arguments M-0...M-9 are available for me to use. So I added these to my deck: * `M-1` <-> `avy-goto-char` * `M-2` <-> `avy-goto-char-2` * `M-3` <-> `avy-goto-char-timer` * `M-g g` <-> `avy-goto-line` By the way thank you u/abo-abo for making `avy-goto-line` default to `goto-line` when the first character is a digit! A really thoughtful and useful feature.
sunnyata · 2022-05-05 07:59
Some basic stuff about jumping to locations in a buffer that many beginners don't know about: *Jump to the mark* (there is only one mark at a time): `C-SPC C-<SPC>`: Set the mark and keep region highlighting off. `C-u C-<SPC>`: Jump back to last mark. *Jump to (any number of) registers*, which die with the session: `C-x r <SPC> R`: Save position of point in register `R`. `C-x r j R`: Jump to register `R`. *Bookmarks* -- any number, long names, last across sessions: `C-x r m <RET>`: Set the bookmark for the visited file at point. `C-x r m BOOKMARK <RET>`: Set the bookmark named BOOKMARK at point. `C-x r b BOOKMARK <RET>`: Jump to the bookmark named BOOKMARK. `C-x r l`: List all bookmarks (`list-bookmarks`). `M-x bookmark-save`: Save all the current bookmark values in the default bookmark file. *Saving text in registers*: `C-x r s r`: stores a copy of the text of the region into the register named `r`. Given a numeric argument (`C-u`) , `C-x r s r` deletes the text from the buffer as well. `C-x r i r`: inserts in the buffer the text from register `r`. Normally it leaves point before the text and places the mark after, but with a numeric argument it puts point after the text and the mark before.
LowCom · 2022-05-05 13:55
I get the error "unknown command" when running M-x which-key-mode
samsjj · 2022-05-05 15:06
I started using Avy recently too. Avy-goto-char-timer can be used everywhere instead of goto-char or goto-char-2
samsjj · 2022-05-05 15:08
You need to install the package which-key and enable it. After that pressing Ctrl- and pausing will show possible completions
dpoggio · 2022-05-05 17:06
Indeed. And a tip: You can use `defalias` for every keymap showed as “prefix”, so that you get a better description. `ctrl-x-4-prefix` does it this way, aliasing `ctl-x-4-map` in `subr.el` (see `C-h v ctl-x-4-map`).
JibStyle209 · 2022-05-06 08:21
Avy is awesome. For those who don’t know, it allows you to position cursor anywhere on the screen via keyboard with minimal number of keystrokes (log n but the log base is number of keys on keyboard),
indopasta · 2022-05-16 13:25
>M-x runs any command or function that can modify the present emacs buffer. This is inaccurate. M-x runs any *interactive* command. Those could modify the present buffer, or could switch to or create another buffer etc.