         (setq hop (string-remove-prefix tramp-prefix-format hop))
         (setq hop (string-remove-suffix tramp-postfix-host-format hop))
         (setq hop (concat hop tramp-postfix-hop-format))
-        (tramp-make-tramp-file-name
-         "sudo"
-         ""
-         (tramp-file-name-host vec)
-         (tramp-file-name-localname vec)
-         hop))
-    (concat "/sudo::" file-name)))
+        (tramp-make-tramp-file-name "sudo" user (tramp-file-name-host vec) (tramp-file-name-localname vec) hop))
+    (tramp-make-tramp-file-name "sudo" user "localhost" filename)))
 
 ;;;###autoload
 (defun sudo-edit (&optional arg)
-  "Edit currently visited file as root.
+  "Edit currently visited file as another user, by default `sudo-edit-user'.
 
 With a prefix ARG prompt for a file to visit.  Will also prompt
 for a file to visit if current buffer is not visiting a file."
   (interactive "P")
-  (if (or arg (not buffer-file-name))
-      (find-file (sudo-edit-filename (read-file-name "Find file(as root): ")))
-    (let ((position (point)))
-      (find-alternate-file (sudo-edit-filename buffer-file-name))
-      (goto-char position))))
+  (let ((user (if arg
+                  (completing-read "User: " (system-users) nil nil nil 'sudo-edit-user-history sudo-edit-user)
+                sudo-edit-user))
+        (filename (or buffer-file-name
+                      (and (derived-mode-p 'dired-mode) default-directory))))
+    (cl-assert (not (string-blank-p user)) nil "User must not be a empty string")
+    (if (or arg (not filename))
+        (find-file (sudo-edit-filename (read-file-name (format "Find file (as \"%s\"): " user)) user))
+      (let ((position (point)))
+        (find-alternate-file (sudo-edit-filename filename user))
+        (goto-char position)))))
 
 (define-obsolete-function-alias 'sudo-edit-current-file 'sudo-edit)
 


;;; Code:
(eval-when-compile
  (require 'subr-x))

(require 'tramp)

(defun sudo-edit-filename (file-name)
  "Return a sudo edit name for a FILE-NAME."
  (if (file-remote-p file-name)
      (let* ((vec (tramp-dissect-file-name file-name))
             (hop (tramp-make-tramp-file-name
                   (tramp-file-name-method vec)
                   (tramp-file-name-user vec)


;;; Commentary:

;; This package allows to open files as another user, by default "root":
;;
;;     `sudo-edit'
;;
