I am using spacemacs. I've written my shortcuts in an org file to not forget them. It has a structure of Description: key, then I go to the next line and enter the next command. For example

*** Latex

Preview at point: SPC m p p
Jump to begin or the end of the environment: %
Use macro: C-c RET
Create environment: C-c C-e or SPC m e

It occured to me, that using an org-table for this would fit quite nicely. By now I have quite some headings with corresponding shortcuts. Is there an elegant fast way to convert my records under a certain heading/tree in an org-table format, so that the text before ":" goes into a first column of a table and the text after ":" in a second column with one table row dedicated for each entry pair? Some custom function defined via defun?

4 Answers 4


For the :, a simple M-x query-replace will quickly get you the | between the two columns. For the | at the beginning and end, M-x query-replace-regexp should do:

  • replace ^ with | for the beginning of the line
  • replace $ with | for the end of the line

Once you've got all the | inserted, pressing tab anywhere in the table will line up all the columns.

  • From *** Latex in the question I concluded that he has several subsections with major modes in his subtree. Therefore, I suggested an alternative approach treating all key descriptions in the subtree at once. (Not only the ones for one major-mode.)
    – Tobias
    Commented Oct 18, 2019 at 16:33

The following approach works for the full subtree describing the key-bindings for all major-modes at once (if the structure of your document is really as you indicated in the question):

  1. narrow to the subtree in question: C-x n s

  2. Type C-<home> to go to the beginning of buffer.

  3. query replace with M-C-% ^\([[:alnum:] ]+\):\( .*\)$ RET |\1|\2| RET.

In the 2nd item I assume that your descriptions only contain alphanumeric characters and spaces.

  • I like the approach with regexp exchange, as I understand, you divide into 1 group until : and second group after : by using curvy braces. Unfortunately this command doesn't find anything to replace, maybe the first expression is not correct?
    – Rareform
    Commented Oct 21, 2019 at 16:00

I often use (C-c |) to convert tab separated areas, so you could perhaps simply replace the colon character with a tab and use that.

Or wrap some elisp around (org-table-convert-region BEG0 END0 &optional SEPARATOR)

Initially I wondered if what you really want is to use the powerful (and I mean to learn this for myself still) Emacs Org's Column View, org-columns(C-c C-x C-c). But having read it again I see that is not appropriate at all to this need.

  • Not what I asked for, still a nice command to discover though.
    – Rareform
    Commented Oct 21, 2019 at 16:00

Ok, I discovered an alternative efficient way for me. I just used M-x query-replace (M-x %) to replace all : (colons) by , (comma). Afterwards I could apply the convertion command C-c | to retain the structure I had. The answer of allsOrts answers it partially, but doesn't mention the trick, that comma can be used for separation to get the 2 columns structure in this case (I am not sure what is meant under replacing colon with a tab).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.