3

I'm using sublime text 3. And I want to display a text with color like a code file in Sublime. But I don't know how to do. Please help me!. Thanks you!

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Kudo Vĩ
  • 33
  • 1
  • 4

4 Answers4

3

You can manually set the syntax of any file using the Command Palette and type "Set Syntax: " or from the bottom right dialog (by default it reads "Plain Text").

If you want Sublime Text to remember your choice, you can also do that from the syntax selection dialog mentioned above, or View > Syntax > Open all with current extension as…".

idleberg
  • 12,634
  • 7
  • 43
  • 70
  • How can I do this for only 1 specific file? And also have it stick across sessions for that file? Right now, if I close the file and reopen it, the syntax highlighting is lost. And I also don't want to set all `*.txt` files as a specific syntax. I use the `.txt` extension as a way of skipping code files from compilation. And these may have code with different languages in them. – kapad Nov 04 '20 at 07:45
2

I think if you need your text file for purposes like note taking, there is a nice hack. Go to View > Syntax and then select haskell. Haskell syntax highlighting is subtle and works fine. To highlight something just capitalise the first letter and it pops in a different colour. Numbers are highlighted in a different colour again, increasing readability. Finally brackets commas etc have different colour which further helps.

0

Well, coloring is based on the syntax, like every programming language has its syntax, but the pure text file is hard to detect the syntax since it can be anything. So if you use the Sublime to coding,try save it as a file with file extension first, then the Sublime will detect by itself, however you could also do this manually.

Hui-Yu Lee
  • 909
  • 8
  • 20
0

The ability to create your own syntax highlighting rules is one of the excellent features of SublimeText.

Have a look here at some other people wanting to build their own syntax highlighting rules:

How to not highlight object keys such as 'do'/'package' as keywords in Sublime?

Sublime Text - C++ Highlight

That explains the basic tools you need to use to do what you want to do.

Following the same ideas there you can build a syntax highlighting scheme for whatever it is you want to achieve in your text file based on whatever syntax rules you are trying to follow. Hard to imagine what those are for a text file without you supplying exact details but if you want to do it Sublime Text gives you the power to do it.

If you give that a try and have trouble with developing the relevant Regular Expression/s to do what you want to do then post what you have done and how it is not working the way you hoped and perhaps we can help you get to the end of the game.

Community
  • 1
  • 1
jwpfox
  • 5,124
  • 11
  • 45
  • 42