                       "")))
           (setq file-name
                 (replace-regexp-in-string (format "\\(?:^\\|[^\\\\]\\)\\(%s\\)"
-                                                  (string-trim-left (car match)))
+                                                  (regexp-quote (string-trim-left (car match))))
                                           path file-name t t 1)))))
     (setq file-name (replace-regexp-in-string regexp "\\1" file-name t))))
 

                    flag (string-remove-prefix "g" flag)))
            (setq path
                  (or (pcase (substring flag 0 1)
                        ("p" (expand-file-name path))
                        ("~" (file-relative-name path "~"))
                        ("." (file-relative-name path default-directory))
                        ("h" (directory-file-name path))
                        ("t" (file-name-nondirectory (directory-file-name path)))
                        ("r" (file-name-sans-extension path))
                        ("e" (file-name-extension path))
                        ("s" (let* ((args (evil-delimited-arguments (substring flag 1) 2))

  "Replace special symbols in FILE-NAME. Modified to include other substitution
flags."
  (let ((regexp (concat "\\(?:^\\|[^\\\\]\\)"
                        "\\([#%\\w]\\)"
                        "\\(\\(?::\\(?:[PphtreS~.]\\|g?s[^: $]+\\)\\)*\\)"))
        case-fold-search)
    ;; TODO Remove s.el dependency so I can offer it upstream
    (dolist (match (s-match-strings-all regexp file-name))
      (let ((flags (split-string (cl-caddr match) ":" t))
            (path (file-relative-name
                   (pcase (cadr match)
                     ("%" (buffer-file-name))
                     ("#" (and (other-buffer) (buffer-file-name (other-buffer))))
                     (_ file-name))
                   default-directory))
            flag global)
        (when path
