How to Create Snippets in Sublime?
Nowadays, Sublime is a very popular text editor in the development field. Sublime text editor provides lots of packages, such as code formatters and PHP syntax, as well as snippets. Snippets are very useful because if you need to write the same code multiple times, you can create a shortcut name for that command content. For example, if you want to write the text "Lorem ipsum", you can just write "lorem" and get the whole "Lorem ipsum" text. In the following example, I created a snippet called "debug" for debugging PHP code.
To create snippets in Sublime, follow these steps:
1. Open Sublime and go to Tools -> Developer -> New Snippet. Alternatively, you can use the shortcut key Ctrl + Shift + P (Windows) or Command + Shift + P (Mac) to open the Command Palette, and then search for New Snippet and select it.
2. A new file with XML syntax will open up. This is where you will define your snippet.
3. Define the snippet's scope by specifying the language(s) that the snippet should apply to. For example, if you want to create a snippet that applies only to HTML files, add
4. Next, define the trigger for the snippet by adding
5. After that, define the contents of the snippet by adding text and placeholders. Placeholders are denoted by $1, $2, etc. and are used to specify where the cursor should go after the snippet is inserted.
6. Finally, save the file with a .sublime-snippet file extension in the appropriate folder for your platform and version of Sublime. For example, on Windows, you can save the file to %AppData%\Sublime Text 3\Packages\User.
7. To use the snippet, type in the trigger text and press Tab or Enter. The snippet will be inserted at the cursor position, and you can then fill in the placeholders as needed.
If you write just "debug" you can find autocomplete with debug snippet and just click on it and find follwing code.
Name Of Snippet
debug
Snippet Result
echo "<pre>";print_r(this);exit;
First Click on "tools" on menubar and click at last "New snippet..." then can see new file open and put following code.
Snippet Code
<snippet>
<content><![CDATA[
echo "<pre>";print_r(${1:this});exit;
]]></content>
<tabTrigger>dbug</tabTrigger>
<!-- 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>
and save name should "dbug.sublime-snippet" and then write "dbug" on your php file and try this....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 10 Image Intervention Tutorial With Example
- How to Get First and Last Word of String in Python?
- How to Count Number of Elements in a List in Python?
- How to Add Years to Date in Python?
- Laravel Csrf Token Mismatch on Ajax Request - Solved
- How to Change Git Commit Message Before Push?
- Angular Fullcalendar Example Tutorial
- Laravel 9 One to One Relationship Example
- Laravel 9 Image Upload Example Tutorial
- Laravel 9 CRUD Application Tutorial Example
- How to Get Last Month Data in Laravel?
- Laravel Maatwebsite Excel Fix Header Row using freezePane()
- Angular 12 Material Datepicker Example
- Angular 10 Install Material Design Example