Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for inserting environments in `org-mode`

I'm using org-mode for organizing myself (very useful so far!). However, it is kind of annoying writting

  #+begin_comment
  ...
  #+end_comment

each time I'd like to insert an environment.

Question

Is there a shortcut to insert the #+begin_ and #+end_ for a given environment?

In the same way C-c C-o comment RET would insert

\begin{comment}

\end{comment}

in latex-mode.

like image 985
Dox Avatar asked Oct 02 '13 19:10

Dox


People also ask

How do I set up Org mode?

To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores. MY PROJECT is the title of the document, this can be anything. This will enable Org mode for this document, no matter what the file-ending is.

Why is Org mode so great?

Org mode is routinely used to build and manage complex workflows. It does this using an elegantly simple syntax that scales from basic markup to full LaTeX typesetting and from plain text notes to literate programs. Everything you need to get started is demonstrated in the example.

What can you do with Org mode?

Org Mode offers the ability to insert source code in the document being edited, which is automatically exported and/or executed when exporting the document; the result(s) produced by this code can be automatically fetched back in the resulting output.

Does vim have Org mode?

vim is a minimal Org mode and Outline mode plugin for Vim providing only syntax highlighting and folding. This plugin aims to replicate Vim's existing Markdown editing experience on Org mode (and Outline mode) files, rather than trying to be a full featured Org mode plugin—that is what Emacs is for.


2 Answers

Org has a facility called "Easy templates": http://orgmode.org/manual/Easy-Templates.html

A template for comment is missing but you can add it with:

(add-to-list 'org-structure-template-alist '("C" "#+begin_comment\n?\n#+end_comment"))

And use it by typing <C followed by TAB.

Alternatively, you could use yasnippet.

like image 156
Michael Markert Avatar answered Oct 05 '22 06:10

Michael Markert


Now the corresponding template section is called Structure Template and the insertion sequence is invoked by C-c C-,. I didn't (require 'org-tempo) which is described to support insertion keys like <s TAB.

The comment environment is already defined in org-structure-template-alist. So the comment would be inserted by

C-c C-, C

It's still possible to add a user defined sequence by, for example,

C-c C-, [TAB|RET|SPC] src python :results output :session

delivering

#+begin_src python :results output :session
#+end_src

(emacs 25.2.2, org-mode 9.2)

like image 36
pjs Avatar answered Oct 05 '22 07:10

pjs