How to (easily) get current file path in Sublime Text 3
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" },
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.
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
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
- Install SideBarEnhancements using PackageControl.
- Click super + shift + P to open the command palette
- In the command palette begin typing
path
until you seeFile: Copy Path
- Select
File: Copy Path
Now the path to file you are working in is copied into your clipboard.
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, 2022Comments
-
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 almost 9 yearsWorks in sublime text 2 as well. So awesome, yet so simple
-
aug over 7 yearsRight clicking images doesn't seem to work though :/
-
Mike Kormendy over 7 years@aug keyword being 'text' in the name Sublime Text.
-
code-8 over 7 yearsHow do you know that
copy_path
is the right command ? How do we know what available ? Is there any docs that I miss ? -
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 viasublime.log_commands(True)
. -
zok almost 7 yearsbeen here before...damn I keep clicking on the title tab to get it
-
Rafiki almost 7 yearstoo bad it's not possible on the tab, you have to switch tab before doing that, sometimes it's a little bit annoying
-
stevec almost 4 yearsIs 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 almost 4 yearsI just realised hovering over the tab gives the full file path