5.5 Expanding ~ to home directory

Home directories on remote hosts can be typed as tilde ~. If possible, they are expanded to the remote user’s home directory on the remote host. Example:

/ssh:user@host:~
⇒ /ssh:user@host:/home/user

This works in general for ssh-like methods, and for sudoedit. These methods allow also the home directory expansion for another user, like

/sudoedit::~otheruser
⇒ /sudoedit:root@localhost:/home/otheruser

For other methods, a home directory can be expanded only if supported. This happens for example for the sftp method. Methods, which require a share directory in the remote file name (afp, smb), use the value of this share directory as home directory:

/smb:user@host:~
⇒ /smb:user@host:/share

Since TRAMP cannot know in advance which share directory is intended to use, this expansion can be applied only when a share directory has been used already.

The methods adb, rclone and sshfs do not support home directory expansion at all. However, TRAMP keeps the home directory in the cache. Therefore, those methods could be configured to expand a home directory via a connection property, See Setting own connection related information. Example:

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/sshfs:user@randomhost.your.domain:")
                   "~user" "/home/user"))

When your remote file name does not contain a ‘user’ part, the connection property "~" must be used instead.