Shortcut for inserting environments in `org-mode`

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.

答案1

org-mode provides a templating system to easily insert structural elements. Although far less featureful than yasnippet, it can come in handy.

The default templates don't include comment blocks, but you can easily add them by putting something like this in your init file:

(eval-after-load "org"
  '(add-to-list 'org-structure-template-alist
                '("C" "#+BEGIN_COMMENT\n?\n#+END_COMMENT" "")))

After this, you can easily insert comment blocks typing

<C

on a line by itself, then <TAB> to trigger the template expansion.

相关内容