Sublime Forum

Save Selected Text to file and run a command


I am looking for a way to save the selected text to a file and run a command against the saved file via keyboard shortcuts. For instance, can I customize a command that will to this when I Ctrl+enter?



You can do this via a custom build system target command that stores the selection to a file; an example of that is outlined in this video (it’s the third example in the video; see the description for a link to the file).

You can then create a custom build file such as the one in the video that has the command you want to execute with the content of the file.

The default build key is ctrl+b, but you could remap it, or create a key binding that always executes a specific build even if that’s not the currently selected one.

1 Like


Terence, thank you so much for your reply and the instructional video. Worked perfectly!

1 Like