Skip to content

Instantly share code, notes, and snippets.

@harthur
Created June 18, 2012 22:12
Show Gist options
  • Save harthur/2951063 to your computer and use it in GitHub Desktop.
Save harthur/2951063 to your computer and use it in GitHub Desktop.
console.log() key binding for Sublime Text

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

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

Inserts a console.log() at the current cursor position, tab once to jump past.

@alexsaw
Copy link

alexsaw commented Jan 3, 2016

Awesome. Exactly what I needed. Thank you!

@yeomann
Copy link

yeomann commented Feb 9, 2016

thank mate!

@andrewcbass
Copy link

Thanks! Keyboard shortcuts for the win.

@Edison767e
Copy link

Thanks!

@dannyn-mirth
Copy link

Does anyone know how to insert a newline first, then insert the snippet on the new line?

This is useful when I want to select a variable and just the shortcut to console log on the next line. This current implement does it in-line which breaks syntax.

@aziaziazi
Copy link

My update to print valueName => value with two cursors : console.log('CURSOR => ',CURSOR)

[
    { "keys": ["super+shift+l"],
      "command": "insert_snippet",
      "args": {
        "contents": "console.log('${1:}$SELECTION => ',${1:}$SELECTION);${0}"
      }
    }
]

@Unkas82
Copy link

Unkas82 commented Feb 17, 2017

You saved my time! thx

@codezyc
Copy link

codezyc commented Mar 24, 2017

can't insert in newLine?

@ryanbsherrill
Copy link

Super awesome. Thank youuuuu

@schester44
Copy link

you can insert a new line using \n

@aegiz
Copy link

aegiz commented Sep 4, 2017

Fantastic 👍

@112KA
Copy link

112KA commented Sep 29, 2017

Using macro, you can output a new line console.log.
https://gist.github.com/112KA/acfd03d6ac9edcd0154932fc055e6c0d

@Avcajaraville
Copy link

Thanks !

@msman
Copy link

msman commented Mar 28, 2018

very cool

@totalBenjick
Copy link

how this works exactly? I have ubuntu in a Spanish keyboard

@samdutton
Copy link

This is great, but (as per previous reply) where are ${1:}, $SELECTION and ${0} documented?

@TimBrunsmo
Copy link

Works like a charm, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment