Auto-insert attribution
below the menu
1. Tools > New snippet…
see the following code
<snippet> <content><![CDATA[ Hello, ${1:this} is a ${2:snippet}. ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- <tabTrigger>hello</tabTrigger> --> <!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- <scope>source.python</scope> --> </snippet>
1.Snippet introduction
content: It must contain <![CDATA[…]]>, otherwise it will not work, Type your snippet here is used to write your own code snippet tabTrigger : The character or string used to trigger the code snippet. For example, in the above example, enter hello in the edit window and press tab to output Type your snippet here in the editor. scope : Indicates that your code snippet will be activated in that language environment. For example, the above code defines source.python, which means that this code snippet will be activated in the python language environment. description : Displays the description of the code snippet, if not written , the default filename of the code snippet is used as the description
2. Snippets can be stored in any folder and have the file extension .sublime-snippet. The default is to store them in the .sublime-snippet folder.
2. Paste the following code into the file
<snippet> <content><![CDATA[ /** * date: ${1:ctrl+alt+shift+d} * author: ${2:} * describes: $ {3:} */ ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>insertdate</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- <scope>source.python</scope> --> </snippet>
The suffix of the saved file is .sublime-snippet
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Insert date quickly
below the menu
1. Tools > New Code Snippet (new plugin...)
see the following code
import sublime, sublime_plugin class ExampleCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.insert(edit, 0, "Hello, World!")
Paste the following code in
import datetime, getpass import sublime, sublime_plugin class AddDateTimeStampCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") } ) class AddDateStampCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d") } ) class AddTimeStampCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.run_command("insert_snippet", { "contents": "%s" % datetime.datetime.now().strftime("%H:%M:%S") } )
The suffix of the saved file is .py
Customize shortcut keys
preferences > key bindings - user
[ {"keys": ["ctrl+alt+shift+d"], "command": "add_date_time_stamp" }, {"keys": ["ctrl+alt+d"], "command": "add_date_stamp" }, {"keys": ["ctrl+alt+t"], "command": "add_time_stamp" } ]
Just save it