Reputation: 75
Hi there and thanks in advance for any help on this.
I have tried hunting here and other places on the web but have not found anything to help. If this is obvious or has been asked before then I am sorry.
I am using Sublime Text 2 and I often end up with a load of open files because they meet a criteria that I have been working on.
I would like to list all those files out a new text file, within Sublime text.
Something like: for each open file write filename (or possibly full filepath) Next
I know I can get there from the open files panel but that only lists the files, there is no interaction with it that does what I expected. To thought I might be able to highlight files and use copy and paste to get a list.
Is this a built-in function that I have missed? Is there already a package to do this? Will I have to work out how to write a plug-in to do this?
Once again, many thanks for any and all assistance on this.
(If it makes any difference this is Sublime text 2, mostly on Windows but I do also switch across to Mac regularly for different jobs)
Upvotes: 6
Views: 1467
Reputation: 744
import sublime
import sublime_plugin
class RunningfileCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().new_file().insert(edit, 0, "\n".join([view.file_name() for view in sublime.active_window().views() if view and view.file_name()]))
Add below content on it:
[{ "keys": ["f12"], "command": "runningfile" }]
Thanks
Upvotes: 2
Reputation: 5114
Here's a hacky and relatively quick way to get something like that:
Ctrl
+Shift
+F
(This brings up the Find in files
dialog).*
button) and search after $
, for exampleCtrl
+F
for normal Search
dialog^_
(caret+space, not underscore) and hit Find All
Ctrl
+Shift
+K
to remove all those content linesThere! Now you have a list of all open files with full path.
More concise:
Ctrl
+Shift
+F
.*
button is on, search after $
Ctrl
+F
.*
button still on, search after ^[space]
-> Find All
Ctrl
+Shift
+K
The other way is to make yourself a small plugin to do that for you at a keystroke.
From the SublimeText2 API, you can get some useful methods:
Class sublime.Window.views() [View] Returns all open views in the window.
Then
Class sublime.View.file_name() String The full name file the file
associated with the buffer, or
None if it doesn't exist on disk.
You can start from an existing plugin. This involves some Python programming skills, though.
Upvotes: 0