How to (easily) get current file path in Sublime Text 3

54,545

Solution 1

Right click somewhere in the file (not on the title tab) --> Copy file path

If you don't want to use the mouse, you could set up a keyboard shortcut as explained here https://superuser.com/questions/636057/how-to-set-shortcut-for-copy-file-path-in-sublime-text-3

Solution 2

To easily copy the current file path, add the following to Key Bindings - User:

{ "keys": ["ctrl+alt+c"], "command": "copy_path" },

Source

Key Bindings - User can be opened via the command palette (command + p on OSX)

Solution 3

Easy to understand using image. On Right Click you will get this.

enter image description here

Transcribed code in image for convenience:

import sublime, sublime_plugin, os

class CopyFilenameCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if len(self.view.file_name()) > 0:
            filename = os.path.split(self.view.file_name())[1]
            sublime.set_clipboard(filename)
            sublime.status_message("Copied file name: %s" % filename)

    def is_enabled(self):
        return self.view.file_name()...  # can't see

Solution 4

Mac OS X - Sublime Text 3

Right click > Copy File Path

enter image description here

Solution 5

A lot of these answers involve touching the mouse. Here's how to do get the path without any mouse clicks using SideBarEnhancements

  1. Install SideBarEnhancements using PackageControl.
  2. Click super + shift + P to open the command palette
  3. In the command palette begin typing path until you see File: Copy Path
  4. Select File: Copy Path

Now the path to file you are working in is copied into your clipboard.

Share:
54,545
MacKentoch
Author by

MacKentoch

Senior javascript lead developper web and mobile (react-native) Github: https://github.com/MacKentoch JSAir app: iOS: (https://itunes.apple.com/fr/app/js-air/id1112141070?mt=8) Android: JSAir (https://play.google.com/store/apps/details?id=com.jsair) website / github repo (yes! it is open source): https://github.com/MacKentoch/jsair-mobile#javascript-air-mobile-application PermisPts app: iOS: permipts (https://itunes.apple.com/fr/app/permispts/id950595671?mt=8) android: permipts (https://play.google.com/store/apps/details?id=com.permispts) website: http://permispts.com Asguard app: iOS: Asguard (https://itunes.apple.com/fr/app/asguard/id1254948065?mt=8) website: https://mackentoch.github.io/asguard-website more on my github

Updated on January 08, 2022

Comments

  • MacKentoch
    MacKentoch over 2 years

    How to (easily) get current file path in Sublime Text 3

    I don't often use ST console (I used it only once to install package manager), but I suppose it could be good way to :

    • get current file path like some kind pwd command.
    • But it doesn't work.

    Does anyone know an easy way to get current file path?

    • to clipboard : better not a strict objective in the answer
    • not necessary by ST command, maybe package?
  • beautifulcoder
    beautifulcoder almost 9 years
    Works in sublime text 2 as well. So awesome, yet so simple
  • aug
    aug over 7 years
    Right clicking images doesn't seem to work though :/
  • Mike Kormendy
    Mike Kormendy over 7 years
    @aug keyword being 'text' in the name Sublime Text.
  • code-8
    code-8 over 7 years
    How do you know that copy_path is the right command ? How do we know what available ? Is there any docs that I miss ?
  • cheshireoctopus
    cheshireoctopus over 7 years
    @ihue - good question; wasn't able to locate copy_path in the docs; if you check out the source I provided above, that user turned on command logging via sublime.log_commands(True).
  • zok
    zok almost 7 years
    been here before...damn I keep clicking on the title tab to get it
  • Rafiki
    Rafiki almost 7 years
    too bad it's not possible on the tab, you have to switch tab before doing that, sometimes it's a little bit annoying
  • stevec
    stevec almost 4 years
    Is there a way to show it on screen? (preferably a keyboard shortcut). Reason is because I have many files of the same name in the same directory, and most commonly have stuff I want to keep on the clipboard)
  • stevec
    stevec almost 4 years
    I just realised hovering over the tab gives the full file path