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

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?

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:

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