Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is the easiest way to find a file path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How do I find the path of a text file?

Click at the end of the box that contains the file name. It's just above the list of files inside the folder, and just below the icons. This highlights the full path to the file. To copy the path, press Ctrl + C .

How do I copy a relative path in Sublime Text?

Adds a “Copy Relative Path” command to the Sublime right-click context menu, which copies the file path of the currently opened file relative to the folder you have open with the greatest path match.

Where the path of the current file is displayed?

The answer is the pwd command, which stands for print working directory. The word print in print working directory means “print to the screen,” not “send to printer.” The pwd command displays the full, absolute path of the current, or working, directory.


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


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)


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

Mac OS X - Sublime Text 3

Right click > Copy File Path

enter image description here


There is a Sublime Package which gives your current file location inside a status bar. I just cloned them directly to my /sublime-text-3/Packages folder.

git clone [email protected]:shagabutdinov/sublime-shell-status.git ShellStatus;

git clone [email protected]:shagabutdinov/sublime-status-message.git StatusMessage;

You have to check/read the description on GitHub. Even it is listed in package control it would not install properly for me. You can actually edit the shell output as you want. If you have the right skills with python/shell.

Looks like this (Material Theme) enter image description here


If you're like me and always click on items in the sidebar just to realize that copying the path only works when clicking in the editor area, have a look at the SideBarEnhancements package. It has a huge bunch of options to copy file paths in a variety of different ways.

Installation is available via Package Control (despite the webpage only mentions installation via manual download).

Note: The package “sends basic, anonymous statistics”. The webpage explains how to opt out from that.

SublimeSideBarEnhancementsScreenshot


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.