In Org-mode, when creating internal links, we have to type full name of the section heading to which we want to link.

Is it possible that the heading name gets automatically filled in when we are creating a new internal link? When creating a new link, we type a few characters and headings matching the characters are shown, and then we can choose from the list.

Maybe some way using helm?


The Org mode info manual has a footnote on (org) Internal links, see the orgmode manual:

(1) To insert a link targeting a headline, in-buffer completion can be used. Just type a star followed by a few optional letters into the buffer and press `M-<TAB>'. All headlines in the current buffer will be offered as completions.

In case your desktop environment intercepts M-TAB before it reaches Emacs you can instead type <ESC> <TAB>.

  • Thanks for the answer. I didn't realize it was right there in the official documentation!! But this doesn't work for my setup. I'm using Spacemacs, so that may be the reason. I'll try it on a bare-bones emacs setup and then revert back.
    – shivams
    Dec 25 '16 at 11:06
  • 2
    For me, the M-<TAB> completion only works when I create links by writing literal markup, i.e. [[<link target>]]. If I use C-c C-l to insert a link, then completion for the link target using M-<TAB> does not work. So, I can type [[*M-<TAB> to complete section titles, but C-C C-l *M-<TAB> does not complete section titles.
    – ntc2
    Oct 10 '17 at 23:00
  • 3
    A small thing that tripped me up: I use electric pair mode, so when I type [[* I actually get [[*]] with point right after the asterisk. The headline completion doesn't work then, even adding a space before the ]].
    – Omar
    Nov 19 '20 at 17:05

I do it using counsel-org-goto. Start a link with [[, run Counsel, select the heading, and then hit M-o i to insert the heading's path. Then close the link or add a custom description.

You can instead use helm-imenu, inserting the selected candidate with C-c TAB, but then you get a bit of extra garbage in the buffer, which you have to delete. I'm sure there's a better way to use Helm for this.

In Spacemacs, if you've enabled the ivy layer then counsel-org-goto will be bound to SPC j i, otherwise helm-imenu will be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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