Sublime Forum

Filename to clipboard

#1

Hello, I’m new to ST and I’ve been trying to replicate a workflow I have in emacs. Here is what I do in emacs:

  • search for a term used in the project (using silver searcher)
  • copy the filename (no path, no extension!) that contains the match to clipboard

Is there a workflow that I can use to replicate this? I browsed the package manager for a while to find something similar and I was unable to find anything close.

0 Likes

#2

Quick script that partially solves this:

import sublime, sublime_plugin, os
class FilenameToClipboardCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		sublime.set_clipboard(os.path.basename(os.path.splitext(self.view.file_name())[0]))

However that requires using the less-than-stellar “find in files”, opening the file, copying the filename, closing the file.

I’m still researching the sublime API, but any help would be greatly appreciated if this is already possible somehow without a script.

0 Likes