diff -u a/org-rename-link.el b/org-rename-link.el --- a/org-rename-link.el 2022-03-22 12:08:45.790727092 -0300 +++ b/org-rename-link.el 2022-03-22 12:25:31.500218923 -0300 @@ -23,8 +23,11 @@ (defun my-org-replace-link-file (from to) (save-excursion (goto-char (point-min)) - (while (re-search-forward org-bracket-link-regexp nil t) - (cond ((string-match-p (concat "attachment:" from) (match-string 1)) - (replace-match (concat "[[attachment:" to "]]"))) - ((string-match-p from (match-string 1)) - (replace-match (concat "[[file:" to "]]"))))))) + (while (re-search-forward org-link-bracket-re nil t) + (replace-match + (cond + ((string-match-p (format "^attachment:%s\\'" from) (match-string 1)) + (format "attachment:%s" (file-name-nondirectory to))) + ((string-match-p (format "^file.*:%s\\'" from) (match-string 1)) + (format "file:%s" to))) + nil nil nil 1)))) Diff finished. Tue Mar 22 12:26:56 2022