12

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?

3 Answers 3

5

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>.

3
  • 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
    Commented Dec 25, 2016 at 11:06
  • 3
    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
    Commented Oct 10, 2017 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
    Commented Nov 19, 2020 at 17:05
2

With helm and in org-mode insert an internal link to a heading by starting a helm search, selecting the target, and typing C-c l.


Typing C-h k C-c l in the helm buffer shows the following description:

C-c l runs the command helm-org-run-insert-link-to-heading-at-marker (found in helm-org-headings-map), which is an interactive compiled Lisp function in ‘helm-org.el’.


You can further bind the helm search to something very convenient, C-.. In .emacs:

(add-hook 'org-mode-hook
      (lambda () (local-set-key (kbd "C-.") 'helm-org-in-buffer-headings)))  ;Outline search.

Note: the inserted link is not as messy as with the helm-imenu method, but does prepend a '*' to the link text:

* Test inserting internal link in org-mode with helm
** A sub-heading target to link to
* Another top-level heading
** Link from here: [[*A sub-heading target to link to]]
1

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 and acknowledge you have read our privacy policy.

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