Friday, May 18, 2018

console.log macro in Sublime Text

Here's how to make a selection macro in Sublime Text. 

Type the word "beer", select it, then press a key to turn it into a console.log statement!

Here's how to do it:

1. Create the console.log template:

Click Tools > Developer > New Snippet...

Paste the following:


<![CDATA[
console.log("$SELECTION");
]]>
log



Save the above as log.sublime-snippet

2. Create a keybinding to the snippet:

Click Sublime Text > Preferences > Key Bindings

Paste this bit into the middle of the keymap:

 {
  "keys": ["ctrl+shift+l"], 
  "command": "insert_snippet", 
  "args": { "name": "Packages/User/log.sublime-snippet" } },

Save it.

To use, type beer in your program. Double-click to select it, then hit your "log this message" keyboard command ctrl+shift+l.

Boom!

console.log("beer");



No comments:

Post a Comment