Org Mode - Blog of Kasra Darvish
This is me

Kasra Darvish

I write to exist beyond time!

Kasra Darvish

14-Minute Read

  1. Insert a link: C-c C-l and then choose org: for example
  2. Edit a link: Same as inserting a link
  3. To link to a url use the following syntax: [[LINK][DESCRIPTION]]
  4. Link to other file formats: You can simply use the syntax above for urls, but instead of a url, provide the path to a file. You can alternatively use the command org-insert-link or keyborad shortcut spc m l l. The default keybinding is C-c C-l. Example: code or audio.
  5. Use counsel to insert internal links to headings in the current file/buffer.
  6. Autcompleting the links simply by ?? I don’t know yet.
  7. Can I link to a markdown from org and have it backlinked? I can link to whatever file I want, but it will break the knowledge graph.

Let’s write something

  • item 1 in order to have a bullet point you can hit space and then * on a new line
    • like this

Headings and Folding

  • create a new heading/lit item of the same level by using cmd+enter or M+ret read it as alt+enter
  • create a new sub heading by using

Folding

  • use shift+tab to fold/unfold all headings at once
  • use tab to fold/unfold the heading under the cursor
  • using M-x clone-indirect-buffer you can have an indirect buffer that is a twin copy of the current buffer but does not update with the other one. It’s very useful to have an outline for a file

Level 3

  • Level 4

    • Level 5

      • Level 6

        • Level 7

          • Level 8

Focus mode or narrowing

You can focus a buffer on a subtree by using C-x n s or the command (org-narrow-to-subtree) which narrows the current buffer to the subtree at point. You can widen the buffer back or remove narrowing by C-x n w

Text Annotations

  • underline
  • italic
  • bold
  • code
  • verbatim
  • stirke
  • :tag:

Embed or include org files in another org file (transclusion)

Why Emacs?

Many platforms have a single item clipboard. Emacs has an infinite clipboard. If you undo a change, and then continue editing, you can’t redo the original change. Emacs allows undoing to any historical state, even allowing tree-based exploration of history. Emacs supports a reverse variable search: you can find variables with a given value. You can perform structural editing of code, allowing you to make changes without breaking syntax. This works for lisps (paredit) and non-lisps (smartparens). Many applications use a modal GUI: for example, you can’t do other edits during a find-and-replace operation. Emacs provides recursive editing that allow you to suspend what you’re currently doing, perform other edits, then continue the original task.

Some keybindings and commands

  1. spc ? shows all the key bindings
  2. spc : or M-x for typing your command
  3. escp goes to command mode. i goes to insert mode
  4. cmd-f activates swiper
  5. C-s activates i-search and after entering your term, you can use C-s to search for next occurences
  6. tramp for ssh
  7. multiple cursor doesn’t work or I don’t know yet
  8. cmd-l goes to line
  9. cmd-’ changes windows
  10. cmd-w close a window
  11. cmd-t creates new workspace/tab/sessions and you can navigate them with M-1,2,3 each number is one of the workspaces
  12. select a region and C-x tab for indention. then use H and L
  13. horizontal split spc-w-s
  14. vertical split spc-w-v
  15. In emacs C-x generally refer to global commands, while C-c refers to language specific commands.

Help

  1. You can see the current value of a variable, any variable, by using the describe-variable function, which is usually invoked by typing C-h v

Themes

I am using chemacs which is a config profile switcher that allows me to select from different configs https://github.com/plexus/chemacs use the following command to choose other configs: emacs –with-profile prime

Files

  1. spc f for anything related to files
  2. spc spc for opening files in all subdirectories.
  3. spc f f or spc . to open directory to select or create a file
  4. spc f r shows a list of recent files (files recent)
  5. spc f p to open config files (packages, init, config)
  6. spc f l to locate a file just by its name. Much like cmd-o in Obsidian.
  1. alt and left/right arrows: jump over 1 word.
  2. alt and up/down arrows: swap two lines.
  3. fn and left/right arrows: jump to the beginning or the end of the file.

Text Edit

copy/cut/paste

  1. cut a peice of text: You can just delete the piece you want and it will be cut but only using emacs keys. Amazing!
  2. If you want to select a region/text and then cut it: C-spc to start highlighting, and then press cmd-x or d to cut.
  3. M-del or C-del to cut the previous word.
  4. M-d for cutting the next word.
  5. cmd-c to copy a text
  6. cmd-v to paste a text
  7. To edit multiple items at once, select the word first and then hit R to select all occurences. Then either add characters or to completely change it first use C-del or M-del to delete sected word and then start typing (isntead of selecting it and then start typing)

Mark/highlight region/text

In doom emacs you could use C-M-SPC to select text. In regular emacs you could use C-SPC to do that. You can then add enclosing parantheses or other things.

Tricks

Read this Nifty Tricks.

  1. use c s ( [ to change a matching parantheses to a matching bracket.
  2. to change inside a matching parantheses, use f ( l to find the starting ‘(’ and then move one character so that you are inside it. Then use er/expand region command to select evreything inside. Then use d to cut and i to go to insert mode and start writing.

Uppercase/lowercase, capitalize

  1. Select a region by C-M-SPC and then run the command upcase-word or upcase-region to make a region all uppercase letter.
  2. Do the same and run the command downcase-word or downcase-region to make a region all lowercase letter.

Column Editing

C-x SPC
down down
C-x r t insert-what-you-want RET

Buffer

  1. spc b for anything related to buffers.
  2. spc b ] for next buffer and [ for previous buffer
  3. spc b B to list all buffers
  4. spc b b to list workspace buffers (Doesn’t list messages, scratch, other unnecessary stuff)
  5. spc b k kills the current buffer
  6. spc b i to list all buffers in a window instead of promp so that you can either open them or kill multiple of them at once.
  7. To delete buffers from the list mention in previous item, just press d on each line you want to kill. Then afte ryou selected all of the buffers you want to delete, press x. Press u for undo selection on each line.

Integrated Terminal

In order to open a file from an integrated terminal such as vterm you can use emacsclient and provide -n flag which means no-wait.

emacsclient -n file.txt

You can then close the terminal if you want and the file stays alive.

Python:

  1. code completion
  2. multiple cursors

Keybindings

  • use C-h b (help binding) in order to see all of the keybindings in the current buffer. This is useful when you find some keybindings for a task, but you want to remap it, so you can search the keybindings to find it and then remap the command.

Keys

use C-h k and then hit the key on your keyboard for which you want to see the description.

Tramp

  • to terminate or abort a running command use C-c C-c
  • to open vterm at current file (whether local or over ssh) use +vterm/toglle command or M-spc o t

DONE make tramp work with vterm, the regular shell is not good enough. I can ssh to server separately with vterm, but I don’t like it. I want to be able to open and close terminal whenever I want.

DONE make tramp work with screen. This might be solved if I can use vterm.

org mode + roam

  • press tab to fold/unfold subtress and shift-tab to fold/unfold the whole document
  • C- creates a new item of the same level (heading, item, or …) even if you are on a heading and there are bunch of stuff below it, this key cord makes a new heading after all of the stuff
  • M-l makes an item 1 level lower, similarly M-h for higher
  • Check this file for more details: basics of org mode
  • How to write latex and code in org mode?
  • Isn’t it easier to use markdown for note taking?
  • To move one line/section up or down use shift-alt-up and shift-alt-down respectively
  • KILL this is my task

Multiple Cursors

Let’s say I want to change all my obsidian references to emacs.

Obsidian is too good and easy to be true. My text editor is obsidian.

Great packages

  1. Magit: the best git client in the known universe
  2. expand-region:
  3. projectile: powerful project navigation/interaction package
  4. smartparens for dealing with expressions and matched delimiters (e.g. brackets and parantheses)
  5. which-key that shows you possible keybindings when you type a partial keybinding.
  6. undo-tree: A powerful way to navigate your editing history
  7. yasnippet for creating custom snippets and templates much like in vscode.
  8. multiple-cursors
  9. org-ref for citations

Some good config/distributions of Emacs

  1. Spacemacs which is a combination of emacs and vim.
  2. Purcell
  3. Prelude
  4. emacs rocks config by Magnar Sveen
  5. Remacs which is emacs ported to rust instead of C.
  6. Scimax an emacs starter kit for scientists and engineers for reproducible research and publishing, with a focus on LaTeX and org-mode.
  7. Graphene for woo users of GUI IDEs like Sublime.
  8. Aquamacs and their github page. This is similar to the previous one but better for macOS users.
  9. configs of the owner of org-roam

Doom

  1. private/default binds SPC u as an alternative to C-u. If you want to disable evil hijacking C-u and C-d, do this before evil loads (ie. in private/xarthurx/init.el):
  2. To install a package from (M)ELPA, first write (package! example-package) in the packages.el file and just reload doom emacs.

Make Emacs better

DONE Add tab support to emacs so I can see all open buffers.

Resources

  1. http://www.jesshamrick.com/2012/09/10/absolute-beginners-guide-to-emacs/
  2. https://www.gnu.org/software/emacs/refcards/pdf/dired-ref.pdf
  3. https://blog.insightdatascience.com/emacs-for-data-science-af814b78eb41
  4. Emacs rocks
  5. https://tecosaur.github.io/emacs-config/config.html
  6. https://tuhdo.github.io/emacs-tutor.html
  7. If you want to start from scratch, you can use better deafults.
  8. A good article about why you should by into the emacs platform.
  9. A glossary for emacs.
  10. What features every editor must have and how emacs does it on quora which is also availbe on this link.
  11. A good video showing some stuff in emacs by Howard Abrams.
  12. A tutorial for emacs calculator.
  13. Emacs as a python IDE.
  14. A youtube toturial to learn emacs from beginning.
  15. Yet another intro to emacs
  16. Why somethings should be difficult to use?
  17. Emacs Nifty Tricks
  18. Emacs Crash Course

Tags and getting things done

You can use getting things done tags simply by creating a new heading and use of the specified tags such as:

TODO do this

PROJ eager

STRT Tasks that I have started. I’m reading a paper

WAIT Tasks that require something else from someone else. image segmentation

HOLD Tasks that are on hold. email from ED

DONE Taks that are finished. Obsidian config

KILL Tasks that are canceled. make emacs perfect

[?] I don’t know

TODO you can specify deadlines by typing the following or simply use C-c C-d and then select a date.

TODO You can schedule tasks by typing the following or simply use C-c C-s and the select a date.

You can change these tags simply by shift+left or right arrow

Using C-c C-t you can change the states

what tags do I need/have?

DONE Create a file for each tag? Or create a file called todo just to put the stuff that I need to do but I don’t know where to put? I can use short-term-memory for that, right? yes!

Do we have tags or something like that :tags: ?

Every headline can contain a list of tags; they occur at the end of the headline. Tags are normal words containing letters, numbers, ‘_’, and ‘@’. Tags must be preceded and followed by a single colon, e.g., ‘:work:’. Several tags can be specified, as in ‘:work:urgent:’. Tags by default are in bold face with the same color as the headline. :tags:

Do we have #tags as well?

Get The Following Done [2/3] [66%]

DONE figure out cut

DONE why headings don’t look different DEADLINE: <2020-12-28 Mon>

This is done by a package called org-bullets. However, in doom emacs you can easily use org +pretty in init.el

TODO Mind map based on the headings same as in Obsidian

Commands

  1. You can use shift-up for increasing date by 1 day and shift-down for decreasing it if you are inside the date < > otherwise it changes the priority.
  2. shift-right and shift-left changes the type of the item: TODO, DONE, WAIT, STRT, PROJ, HOLD, KILL

Something

TODO Use shift to select text in org mode and another key to change priority and task

check boxes [3/3] [100%]

  • cut paste with cmd
  • headings are different

tree

Code blocks in org mode

  1. Use the headings shown in example below to write a code inside org file. Alternatively, you could type <s and then hit tab to automatically inser t a code block.
  2. To run the code use: C-c C-c
  3. For python you have to use RET to see the results, otherwise it always says : None

Example

return 'Hello Emacs and org mode!'

LaTeX

  • It’s perfect and I can have equation numbering as well.
  • You don’t even need to add the $ sign dude.
  • If you hit enter in normal mode when you are inside a latex part, it renders it. How cool is that?

Let’s try an inline math first: \(x^2 + y^2 =1\).

Let’s try it without $ sign:

\begin{equaiton}\label{eq:org} p(a \vert b) = \frac{p(a,b)}{p(b)} \end{equaiton}

Can I refer to this equation with \ref{eq:org}?

Now, let’s try an elaborate formula with number.

\[\begin{equation}\label{my-eq} e = mc^2 \end{equation}\]

in equation \(\ref{my-eq}\) we have einstein.

Figures and Graphics

You have to options to insert and link to graphs in your org files.

  • Using latex

    \begin{figure}[ht] \centering \includegraphics[width=1.0\columnwidth]{/Volumes/GoogleDrive/My Drive/Apps-Storage/Prime/BrainPrime/Resources/Research/Paper-Summary-Figures/Variational-Sequence-Labelers.png} \caption{VSLs} \label{fig:vsls} \end{figure}

    Then you can link to it by \(\ref{fig:vsls}\).

    Using this method results in a correct numbering of figures while in the next mehtod it’s a bit harder.

  • Using org-ref

    You can simply link to graph 1 by org’s link syntax which is [[figure's label][custom name]].

    You can easily add the graph by the following syntax.

Citations and org-ref

you can simply use org-ref-helm-insert-cite-link or C-c ] to search for the citation you want to add.

Markdown

$x_2^2 + x_1^2 =1$

Mermaid and diagrams

</ox-hugo/deleteme.pdf>

Export

There are packages prefixed with ox (org export).

  • ox-twbs: export a good looking html.
  • ox-gfm: export to github flavored markdowon
  • Use C-c C-e to see the export menu

PDF

When exporting to pdf thorugh latex using command org-latex-export-to-pdf, it deletes all extra intermediary files (aux, log, etc) by itself.

HTML

Use the command org-html-export-to-html. This is better than latex and is more readable.

Beamer

use a package called ox-beamer to make presentation-like pdfs.

Tables

  • To create a table just type | some | data |RET |- tab
data Some
12 hi
34 bye
  • Use shift-right to swap a cell with the cell in its right.
  • Use M-right to move a column to right.

TODO I have to find a way to let me have tables not go to next line.

Org-Agenda

  1. You have to add files to org-agenda-files so that tasks can be shown there. To do so use C-c [. You can also remove files from org-agenda-files by C-c ]

TODO how to use org-agenda and calendar for scheduling and time tracking?

TODO how to use habit tracker of org mode?

DONE in order to add closed date when you mark a task as DONE or KILL, you can add (setq org-log-done 'time) to your config files.

Zettelkasten in org mode

The following packages are available to help you

  1. org-zettelkasten which is not maintained anymore
  2. org-roam which is my favorite so far. Their website.
  3. org-brain: I don’t like this one. Very ugly.
  4. zetteldeft

Org-Roam

You can have automatic file renaming using org-roam. For that you only need to change the title of the file you want to rename.

Change the title, but also use M-x rename-file and that would update the org-roam database and all the backlinks.

DONE figure out why org-roam graph doesn’t work?

It makes the graph as SVG file, so the problem is not with org-roam but rather doom emacs or grpahviz that makes the graph. It can open inkspace svg files.

You can use org-roam-server to see the knowledge graph. To do so just run the command org-roam-server-open which you defined that is different from org-roam-server-mode because you have to disable smart-parens since they have conflict. After running this command you can open a tab in your browser with this url http://127.0.0.1:8080/ and see your graph.

TODO change the format of captured files to not use dates.

Introduction to org-roam by its author

References

  1. A great intro to org mode by Harry Schwartz. Also check his dot files and emacs config.
  2. A list of talks from EmacsNYC.
  3. Emacs rocks
  4. The ultimate guide to organize your life in plain text with org.
  5. Citation in emacs org mode using org-ref.
  6. A short read on productivity with org mode.
  7. Writing PhD thesis in org mode
  8. org tutorials
  9. some org mode features you may not know
  • None
  • None
comments powered by Disqus

Recent Posts

Categories

About

I'm a Ph.D. student interested in Artificial Intelligence, Machine Learning and intelligence in its abstract form