0

For a file containing

[[./img/a.jpg]]
[[./img/b.jpg]]

the command org-toggle-inline-images, which is bound to C-cC-xC-v, will display the images within the buffer.

But suppose that the first image is already displayed, and you just typed in the second. Is there an alternative to toggling twice C-cC-xC-v C-cC-xC-v to view the new image? Is there perhaps an electric mode that searches for the existence of an image once the pair ]] is typed? Is there another shorthand?

1 Answer 1

1

org-display-inline-images can be called instead. It takes a REFRESH argument that should do what you want. Do C-h f org-display-inline-images to get its doc string:

(org-display-inline-images &optional INCLUDE-LINKED REFRESH BEG END)

Display inline images.

...

When optional argument INCLUDE-LINKED is non-nil, also links with
a text description part will be inlined.  This can be nice for
a quick look at those images, but it does not reflect what
exported files will look like.

When optional argument REFRESH is non-nil, refresh existing
images between BEG and END.  This will create new image displays
only if necessary.

BEG and END define the considered part.  They default to the
buffer boundaries with possible narrowing.

So you could do M-: (org-display-inline-images nil t). Assuming that it does what you want, you can bind it to a key:

(define-key org-mode-map (kbd "C-c v") 
    (lambda () (interactive) (org-display-inline-images nil t)))

Choose a key that's not defined already and is meaningful to you.

2
  • Super. Small detail: Please replace )) with ))) on the define-key line.
    – Sam
    Feb 27 at 6:57
  • Thanks! Sorry for the typo.
    – NickD
    Feb 27 at 7:01

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.