41

I found the command SPC m x c to insert a small code snippet like ~~. I would like to insert a longer snippet like

 #+BEGIN_SRC 
 #+END_SRC

Is there a command to do this? I found a way to add it for markdown, which is SPC m x c

JuanCaicedo
  • 679
  • 1
  • 6
  • 11

1 Answers1

91

February 2020 update to this answer: From org version 9.2, the old easy templates referred to in this answer is no longer active by default, see this answer for more info: Why do easy templates, .e.g, "< s TAB" in org 9.2 not work? along with the new way to access easy templates which is invoking "org-insert-structure-template" C-c C-,, or using Spacemacs: , i b

Original answer:

Yes, it's called easy templates.

Org mode supports insertion of empty structural elements (like ‘#+BEGIN_SRC’ and ‘#+END_SRC’ pairs) with just a few key strokes. This is achieved through a native template expansion mechanism. Note that Emacs has several other template mechanisms which could be used in a similar way, for example ‘yasnippet’.

To insert a structural element, type a ‘<’, followed by a template selector and ‘TAB’. Completion takes effect only when the above keystrokes are typed on a line by itself.

For your precise question: <s then TAB.

Note it's not specific to spacemacs, since it's from native org-mode

Sergio
  • 103
  • 4
JeanPierre
  • 7,323
  • 1
  • 18
  • 37
  • 3
  • 2
    @shark8me It works in Spacemacs. Just go into the `Insert` mode and then press ` – shivams Nov 04 '17 at 18:59
  • 19
    Note, this is changing a bit from Org 9.2. For "` – rasmus Apr 11 '18 at 22:48
  • @rasmus `(require 'org-tempo)` did the trick for me, in Spacemacs. Thanks! – Sankalp Jun 04 '19 at 22:30
  • 6
    FYI, this behavior changed in Org 9.2. The new method is given in the release notes. Basically, press `C-c C-,` for a list of templates and then select `s` for source. @rasmus above explains how to continue using the old way in newer versions of org-mode. https://web.archive.org/web/20190117084828/https://orgmode.org/Changes.html – Lorem Ipsum Aug 26 '19 at 23:49