I have tried to find command, plugin or anything that can do this. Essentially I need two keyboard shortcuts. One to copy current file path(only current directory, not file name). Another to copy only file name(with extension eg; "test.txt" ).
You can do this with a simple plugin such as this (see this video on using plugins in Sublime if you're not sure how to put it in place):
import sublime
import sublime_plugin
import os
class CopyFilePathCommand(sublime_plugin.TextCommand):
def run(self, edit, name=False):
path, filename = os.path.split(self.view.file_name())
sublime.set_clipboard(filename if name else path)
self.view.window().status_message(
'Copied file %s' % ("name" if name else "path"))
def is_enabled(self, name=False):
return self.view.file_name() is not None
This implements a command named copy_file_path
which will copy the path of the current file to the clipboard by default, switching to copying the name of the file instead if you pass true
for the value of the name
argument.
A message is displayed in the status bar to tell you which thing was copied, and the command will disable itself for any file that hasn't been saved to disk yet (since it would thus have no path to copy).
Sample key bindings might look something like the following:
{ "keys": ["ctrl+shift+alt+p"], "command": "copy_file_path", "args": {"name": false}},
{ "keys": ["ctrl+shift+alt+f"], "command": "copy_file_path", "args": {"name": true}},