Search code examples
emacscd

emacs cd for all splits


In emacs you can do M-x cd to change the default directory.

I usually have 5 splits/windows, so the cd I do in the first split does't affect the others. What If I want the cd to affect all my splits/buffers. Is there an alternative command I can use?


Solution

  • There's nothing built-in but it's not too hard to write the function by hand:

    (defun cd-all-windows (dir)
      (interactive "Ddirectory: ")
      (dolist (window (window-list))
        (with-current-buffer (window-buffer window)
          (cd dir))))
    

    Put that in your .emacs and you should be able to run M-x cd-all-windows to get the desired effect.