Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a snippet of text using a keyboard shortcut in Sublime Text?

How do I set a shortcut for inserting console.log() and wrapping it around my current selection in Sublime Text without installing any plugin or extra third-party stuff?

like image 224
myusuf Avatar asked Jun 12 '14 14:06

myusuf


1 Answers

So I found the answer. Thought I'd add it here for others:

Go to Sublime Text 2 > Preferences > Key Bindings - User and add this JSON to the file:

[
    { "keys": ["alt+d"],
      "command": "insert_snippet",
      "args": {
        "contents": "console.log(${1:}$SELECTION);${0}"
      }
    }
]

Inserts a console.log() at the current cursor position on pressing alt+d.

Reference: https://gist.github.com/harthur/2951063

like image 93
myusuf Avatar answered Oct 13 '22 01:10

myusuf