Sublime Forum

Automate 'use strict'; at top of new .js files

#1

I’m coding Node.js and creating a lot of .js files. I want ‘use strict’; to appear at the top of every .js file.

When I create a file in Sublime Text I select File|New File and then save it as blah.js. Can I set things up so that as soon as the file is saved Sublime Text notices that it’s a .js file and inserts ‘use strict’; at the top of the file?

If not, what’s the most efficient way to get this ubiquitous line onto the top of a new .js file?

0 Likes

#2

Maybe have a look to https://packagecontrol.io/packages/FileHeader

1 Like

#3

This works very well. Thanks!

There is a minor bug in the package: It you place an empty line at the bottom of the header template it will be stripped away. However, this is easy to work around. If you’d like a blank line at the bottom of your header, put two blank lines at the bottom of the header template; only the final blank line is stripped away.

0 Likes