As the title suggests, I want to rename several tags only in agenda files.

So, a tag1 will become tag11, taga1 will become someothertag, etc.

I can do it with C-a m tag1 * B + tag11 RET C-a m tag1 * B - tag1 RET

But that is too cumbersome, especially, if you have to do it for several tags.

Any other quicker methods?


You can write a function that check if an entry has "tag1" and if so change it to "tag11":

(defun change-tag (old new)
  (when (member old (org-get-tags))
    (org-toggle-tag new 'on)
    (org-toggle-tag old 'off)

Now all you have to do is apply that function to each entry that has "tag1". You can do this with org-map-entries:

(defun org-rename-tag (old new)
  (interactive "scurrent tag: \nsnew name: ")
   (lambda () (change-tag old new))
   (format "+%s" old)

Call this with M-x org-rename-tag and it will prompt for the old and new tag names and proceed to change the tags everywhere in the current buffer.

  • Thanks. Any way we can do it for all agenda files at one go? – deshmukh May 13 '18 at 4:29
  • 2
    If you change the nil in org-map-entries to agenda it will map the function over all agenda files. You could also map it over a single tree or a region. – erikstokes May 13 '18 at 17:51
  • Thanks. This works perfectly. Also, I looked up org-map-entries in the documentation to figure out what was happening. Will remember to do it going forward – deshmukh May 14 '18 at 6:19

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.