JavaScript
Article

Mapping a new tab command in Sublime 2 Text

By Sam Deering

console.log

I found myself typing in console.log like hundreds of times a day (although you could use a program like ‘hotkeys’ to map your commands). I decided to create a sublime snippet which does this for me by simply typing “co” and pressing tab. It also puts the cursor in the debug field which is quoted and print out the console.log command into the IDE.

Related posts:

Description:

This awesomely simple Sublime snippet lets you console.log in millseconds (well it’s under a second for sure!). Cursor action loads directly to the debug message (which is automatically wrapped in quotes) and if you press tab again cursor action loads to the log command so you can change it to console.debug or console.dir as you wish.

Filename:  console_log.sublime-snippet
Trigger: co (tab)
Output: console.log('debug message');
Usage: co [tab] - load the console.log() command

Installation:

Copy the snippet into a file called “console_log.sublime-snippet” in the JavaScript folder:

C:Documents and SettingsdeeringsApplication DataSublime Text 2Packages

Or you can type “%appdata% into cmd to load the directory.

The sublime 2 snippet:


    < ![CDATA[console.${2:log}('${1:debug message}');]]>
    co
    source.js,source.js.jquery
    Console log

Conclusion:

From this simple example you should be able to start mapping any commands to generate new snippets to use with Sublime 2. If anyone has created any other Sublime snippets please share! :)

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.