How to display a text file (.txt) as a code file with color in Sublime Text 3 - sublimetext3

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!

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…".

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.

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.

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.

Related

Sublime Build 3126 : How to highlight all the line that contains my found phrase after searching?

I have an original version of Sublime Build 3126. Please, I need to learn the following if possible.
Basically, when I search for a term and click on the found line from the results window, I would like the Sublime editor to highlight the whole line that contains my term. At the moment, every time I click on the search result entries, I need to look again through the page for the line that contains the term. The Sublime editor is only highlighting the line number which is very hard to notice.
Ideally speaking, the whole line that contains the term might be highlighted and the term itself must be boxed/highlighted in a different way for instant identification.
If anyone knows how to adjust that to make it clear and easy to identify the found terms, it would be greatly appreciated.
I am using the Ubuntu version of Sublime.

How to highlight variables in sublime?

How to highlight variables in sublime text 3? like in netbeans
Your question is not very clear, but here are some options. First, if you're just trying to get variables highlighted differently, you'll need a color scheme with more options than the default Monokai. There are many available on Package Control, but one in particular that I know will work (since I'm its author) is Neon:
You can use the excellent tmTheme Editor to see how this or hundreds of other themes will look (sort of) in different languages. (I say "sort of" because the highlighting engine used on the website is different than the one in Sublime, so there will be some differences. Overall it's pretty good, though.)
On the other hand, if you're trying to highlight all the instances of the $page variable, you'll have to do two things. First, double-click on $page to select it. Then, select Find -> Quick Find All (or use its keyboard shortcut) to select all the instances of $page in the document:
The gutter icons and colored underlines are from the BracketHighlighter plugin
Unfortunately, this is the only way to get this to work when using PHP and other languages like JavaScript that denote variables with a $ or other symbol. If we were to use Python, for example, you could just double-click on page and it would look like so:
As you can see, all the other instances of page have boxes around them. This behavior is hard-coded into Sublime, so while it can be turned on and off, it can't be modified or told to recognize other characters in any way.
Good luck!

Sublime Text: ignore double quotes and display correct colors for HTML tags

I used to write HTML attribute values without double quotes. That makes the HTML code look very clean. Take my another answer as an example.
However, such a style causes Sublime to display tag colors incorrectly. In the following picture, since <div id=wrapper> has no double quotes around wrapper, Sublime does not show any color after that line (but how come everything looks OK before that line?).
Is there any way that I can set Sublime to ignore the double quotes and display correct colors?
What you need to do is redefine the syntax definitions in Sublime Text. You can also do this on the user level. Two great resources for doing this are here and here. They're very well written.
With that said, I’m using build 3083 right now and I can’t replicate your issue. A quick update might be all you need. I hope this helps.
Sublime Text has a setting called "HTML/XML Attributes" that can be customized to handle this scenario. You can add the following setting to your Sublime Text user settings file to ignore the double quotes:
Json
"auto_complete_html_attributes": false
This setting will turn off auto-completion for HTML/XML attributes in Sublime Text and allow the display of tag colors correctly. To access the user settings file, go to Preferences > Settings.

GUI text editor with syntax highlighting + background text highlighting

Looking for a GUI based text editor that has syntax highlighting for some of the more commonly used languages, plus manual text backround highlighting. Like you can permanently highlight selections of text, not just 'current line highlighting' or changing the default background color for 'currently selected' text. I thought notepad++ had this, but I haven't been able to tell how to access it if so.
I've only been able to find editors that do one or the other so far. Mostly just want this for studying purposes.
Have a look at AvalonEdit from the SharpDevelop project. Might be what you're looking for. Or at least a good basis to develop your own.

Vim for Word (or something like it)

Are there any rich-text editors that have Vi(m) keybindings? Specifically, something like Word where I can compose a document with colors, headings, et al. but use Vi(m) bindings to move around and compose?
So if you have to use MS Word and want vim key bindings, there is an add on, but if you are not bound to that I would def. go for LaTeX + the vim latex suite.
Are you familiar with Latex?
Simply put it allows you to format your documents in plain text using tags or commands.
You then "compile" your document into the final format .pdf,.ps, etc.
Ex:
\documentclass{article}
\title{Cartesian closed categories and the price of eggs}
\author{Jane Doe}
\date{September 1994}
\begin{document}
\maketitle
Hello world!
\end{document}
This will allow you to write in vim, but still get professional non plain text output for your documents.
If you like Markdown or Latex, you could use the free open source Rstudio editor, with VIM-mode enabled. Export as either Word, PDF, or HTML etc.
Download Rstudio:
https://www.rstudio.com/products/RStudio/#Desktop
Read about markdown:
http://rmarkdown.rstudio.com/
If you wish to use vim for text editing, but want to, for example have text in different colors, bold it and such ... you can use Txtfmt plugin. It enables you, by using special characters, to "prettify" plain text files a little. They can look quite nice, and it comes handy if you're used to vim, and are, for example, writing documentation for your programs which you'll later just get in word, and make an adjustment or two, and ship off.
If you want to (or have to) stay with Word and don't want to shell out $100 for a ViEmu license, you can try using this AutoHotKey script for providing some basic vi-like functionality. The repo linked also provides a standalone exe to get the same without using AutoHotKey.
There are many good reasons to ditch word entirely, but sometimes that's just not an option :(
The Txtfmt plugin definitely provides the functionality you are looking for. It's a bit like having "rich text" capability for plain text in Vim.
Txtfmt (The Vim Highlighter)
Screenshots
The latest version supports 8 configurable foreground and background colors, as well as all combinations of bold, underline, italic, etc... The highlighting is token-based, but the tokens are rendered invisible by the syntax, and can be inserted with very convenient and intuitive mappings, which don't require you to remember anything: e.g., "bold-underline" could be specified with a string such as bu or ub. The version under development even supports visual maps, which will permit you to select some text and say (for example) "Make this text red, bold-italic", and have the plugin handle insertion/removal of the appropriate tokens automatically. (It's really quite simple and intuitive, however, even with the non-visual mappings.)
Although the plugin is highly configurable, the default settings are appropriate for most users, and the author is more than happy to answer any setup or usage questions...
There's a way of configuring Abiword to use vi key bindings
You can use the text editor of your choice with vim keys (vim, emacs, sublime, atom, vscode ,etc.) and write your document in markdown. Then use an open source tool called pandoc to translate it into almost any other markup language that you want. It is possible to compile your document to rich text formats including MS Word or even MS Powerpoint.
You can costumize your output by using a template.
Pandoc has extensive documentation and uses a richer markup syntax that allows you to do pretty much anything you want with the text. It is being actively developed by the community. Almost any major text editor has a few plugins for pandoc too.
You can use GlobalVim.
It can simulate vim modes and commands in most editing area.

Resources