Insert a new heading after numbered list in org-mode

In org-mode in emacs, M-<RET> will add either a new heading or if your insertion point is between a list item and a heading, it will add a new list item. This is not always desirable. To add a new heading try C-U M-<RET>.

I only discovered this as I got frustrated with org-mode insisting on adding an item to the list rather than creating a new heading. The emacs way around problems like this is to prefix the command with C-U to make it do something slightly different.

Converting lines of text into a numbered list in org-mode

Recently I had a list of things in a org buffer that I wanted to turn into a numbered list but couldn’t find an elegant way to do it.

The solution I came up with was to use a regex-replace to insert 1. in front of each line. Then I used org-mode’s C-c C-c to renumber the lines.

I also asked on #org-mode on irc. Two interesting solutions were suggested.

  1. use string-rectangle
  2. use the string-rectangle function via the keyboard shortcuts: C-x r t 1 . <SPC>

    string-rectangle is new to me but seems as though it could be very useful. Thanks quicksilver for that suggestion.

  3. use org-mode’s org-toggle-item
  4. which is described as:
    Insert separator line in table or modify bullet status of line.
    Also turns a plain line or a region of lines into list items.
    Calls `org-table-insert-hline', `org-toggle-item', or
    `org-cycle-list-bullet', depending on context.

    The trick is to prefix it with C-u which supplies ARG to the function org-toggle-item which changes each line in a region into an item.

    C-u C-c - then S-right until you get to the list type you want.

    Thanks Thumper_ for that suggestion.

UPDATE: zhen pointed me to rectangle-number-lines, which I did look at before but it’s default option numbers the lines without the full stop after each number. As I wanted this for org-mode, I really wanted the numbers to be formatted as “1. “. After reading the help on rectangle-number-lines though, I found that if you prefix it with the argument command C-u it will ask you for a starting number and the format of the numbers.

∴ Select a rectangle at least one column wide of the lines you want to number then
C-u C-x r N <ENTER><backspace>.<spc><ENTER>