Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting syntax highlighting for individual file

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?

like image 939
Keith Morris Avatar asked Jul 15 '14 01:07

Keith Morris


People also ask

How do I enable syntax highlighting?

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.

How do you change file associations in PyCharm?

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.

How do I enable syntax highlighting in Notepad ++?

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”.


1 Answers

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).

enter image description here

You can clarify the actual status of this feature in that ticket.

like image 144
LazyOne Avatar answered Oct 10 '22 01:10

LazyOne