Often I write small command line utilities and will use alternate languages to create these scripts (e.g. node.js, php, etc.). When I create these files, I use a standard #!
to start the file to indicate to the shell what the intepreter should be. For example, for a node.js script, I'd put this at the top:
#!/usr/bin/env node
In PHPStorm/WebStorm, the syntax highlighting works fine as long as the file has the extension of .js
but if I drop the extension, there is no syntax highlighting. In SublimeText, I can use the command pallet to set the syntax of the current file to JavaScript (for example) by typing the Ctrl+P/Cmd+P + SSJS (Set Syntax JavaScript)
Is there any way within the JetBrains IDE's to set the syntax of an individual file beyond just registering a file type based on file extension?
After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.
Press Ctrl+Alt+S to open the IDE settings and select Editor | File Types. Click Associate File Types with PyCharm and select the file extensions you want to open with the IDE. Click OK and close the dialog.
To configure syntax highlighting, click on “Language” in the top bar, then click the letter the language starts with, and then the language. If you want to define your own language, click on “Language” again, then click on “User Defined Language”, third from the bottom, and then click “Define your language”.
PhpStorm/WebStorm (as well as whole IDEA platform) does not have ability for user to change custom language / syntax highlighting on the go (whenever you want) -- it has to be associated with certain file type.
Of course -- implementing this (shebang recognition) via plugin is possible -- just like it is implemented for PHP files.
On one hand there is http://youtrack.jetbrains.com/issue/WEB-11842 -- vote/star/comment to get notified on progress
On another hand -- it works for me in PhpStorm (v8 EAP build) -- as you can clearly see file is recognized as JavaScript (sorry, I have nodejs plugin installed, but it is not configured/no nodejs sources/SDK as I do not use it myself).
You can clarify the actual status of this feature in that ticket.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With