The following tutorial column from sublime will introduce how to set up your own code snippets in Sublime3. I hope it will be helpful to friends in need!
Set your own code snippets in Sublime Text 3
When writing code, you often write the author, creation time, etc. in the comments. This way Now that you have left your mark, today I will teach you how to build your own comment code blocks (Snippets).
Sublime Snippets (Code Snippets)
Sublime text 3 Snippets are an important function you need when you need to repeatedly enter the same snippet of text or code.
Snippets can be stored in any package folder, but for simplicity, it is recommended to save them in the Packages/User directory first.
The file format of Snippets is .sublime-snippet, usually Snippet The structure is as follows
<snippet> <content><![CDATA[Type your snippet here]]></content> <!-- Optional: Tab trigger to activate the snippet --> <tabTrigger>xyzzy</tabTrigger> <!-- Optional: Scope the tab trigger will be active in --> <scope>source.python</scope> <!-- Optional: Description to show in the menu --> <description>My Fancy Snippet</description> </snippet>
As long as we replace the content in CDATA with our own, we can complete the writing of the simplest Snippets.
Create your own Snippets
Next we will use our own code comments as an example to write a Snippet.
First, select Tools | Developer | New Snippets... in the sublime menu bar, and then enter
<snippet> <content><![CDATA[ /* * @author: ManiaU * @createTime: ${1:time} * @description: ${2:description} */ ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>comm</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.js</scope> </snippet>
where content is the content of the Snippet, and tabTrigger is what you input that can be recognized as a Snippet. Scope represents the effective file format. In content, ${} is the content that can be selected by the tab key after you finish typing. ${1:} is the content that is selected directly after you finish typing. ${2:} is what is selected by pressing tab once. content, and so on.
Then save it as comment.sublime-snippet. Next, enter comm in a js file, press the tab keyboard, and your Snippet will appear.
Time input plug-in
Although Snippet is generated, the time is still not fixed. Next, create your own plug-in and select Tools | Developer | in the sublime menu bar. New Plugin..., enter the following content
import sublime, sublime_plugin from time import localtime, strftime class InsertDatetimeCommand(sublime_plugin.TextCommand): def run(self, edit): sel = self.view.sel(); for s in sel: self.view.replace(edit, s, strftime("%Y-%m-%d, %H:%M:%S GMT%z", localtime()))
and save it as insert_datetime.py, then add
{ "keys": ["super+ctrl+t"], "command": "insert_datetime" }
in Preference | Key Bindings. This means that you can insert the time by pressing ⌘ Control T. , with the above Snippet, after inserting comments, adding time and description, you can easily generate your own comments, as follows
/* * @author: ManiaU * @createTime: 2017-03-14, 22:33:00 GMT+0800 * @description: This is a test! */
Postscript
Of course, Snippets It’s not only useful. You can configure various fragments in your environment, which can greatly improve work efficiency. Let’s explore together!
The above is the detailed content of Teach you how to set up your own code snippets in Sublime3. For more information, please follow other related articles on the PHP Chinese website!

SublimeText is suitable for developers who pursue speed and simplicity, while VSCode is suitable for users who need strong scalability and integration capabilities. 1.SublimeText is known for its lightweight and fast response, with GotoAnything and multi-select powerful. 2. VSCode is known for its scalability and IDE functions, with built-in Git and debugging tools, and IntelliSense improves development efficiency.

SublimeText's plug-ins and packages can be installed and managed through PackageControl to improve programming efficiency. 1. Install plug-ins such as BracketHighlighter to simplify code reading by highlighting bracket matching. 2. Use SublimeLinter to configure pylint to implement real-time code checking. 3. Use SideBarEnhancements to customize the sidebar function to optimize file management.

SublimeTextisfreeduringanunlimitedtrial,buta$99licenseisrecommendedforregularuse.1)Thetrialallowsfullfeatureaccesswithouttimelimits.2)Alicenseoffersperpetualuse,futureupdates,andremovespurchasereminders,enhancingproductivityandsupportingdevelopers.

SublimeText can greatly improve work efficiency. 1) Multiple selection and multicursor functions allow editing of multiple positions at the same time, 2) Command panel provides fast function access, 3) Macros and fragments can automate common operations, 4) Optimized configuration and shortcut key use can improve performance and efficiency.

SublimeText offers a free trial, but ultimately requires a paid purchase for a permanent authorization. 1) During the free trial period, users can experience its functions, but they will receive a purchase prompt. 2) After purchase, users can use it permanently, no subscription fee, and access more plug-ins and themes.

ThemaindifferencesbetweenthepaidandunpaidversionsofSublimeTextaretheremovalofstatusbarremindersandoccasionalpop-uppromptsinthepaidversion.1)Unregisteredversion:fullyfunctionalwithallcorefeatureslikesyntaxhighlighting,codecompletion,andcommandpalette,

SublimeText is worth buying. 1) Its simple interface and powerful functions, such as multi-line editing and GotoAnything, improve development efficiency. 2) Rich plug-in ecosystem, such as Anaconda, enhances the development experience. 3) Although the price is $70, its performance and fluency are great value for professional developers.

SublimeText is loved by developers for its powerful code completion and syntax highlighting capabilities. 1) Code completion can automatically prompt function names, variable names, etc. to improve programming efficiency. 2) Syntax highlighting distinguishes code elements through different colors to improve readability and error detection speed.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
