问题
I'm trying to get the path of the current file + the file's name (without extension) in a Key Binding file in Sublime Text 2. $file_path
or ${file_path}
are both not working.
The reason is that I want to execute an *.exe file, which was built before (but don't want to both build and execute in one step). Any ideas?
Greetz
回答1:
you may try the sublime-snippet, this is my code:
#filename: filename.sublime-snippet
<snippet>
<content><![CDATA[$TM_FILENAME]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>fn</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.python</scope>
<!-- Optional: Description to show in the menu -->
<description>the current file name</description>
</snippet>
when you type 'fn' in python source files, you will get your filename.
回答2:
Sublime offers a command called copy_path
which will copy the current file's absolute path to the clipboard. Unfortunately, this includes the file extension. But if you're familiar with how to roll your own quick plugin, you can issue copy_path
therein, and perform some basic string manipulation to strip the file extension. If not though, you can bind copy_path
to a key combination and work from there.
来源:https://stackoverflow.com/questions/11847204/get-file-path-file-name-in-a-keybindings-file-in-sublime-text-2