How do I make Sublime Text recognize my .sublime-syntax file - sublimetext3

Using PackageDev I created a myLanguage.sublime-syntax File, as it's documented everywhere, e.g. in https://www.sublimetext.com/docs/3/syntax.html.
I saved it in .../Packages/User. But I can't see the new syntax in View->Syntax. There must be a step missing!?

Related

How to set default file extension of saving file for specific syntax in Sublime Text 3

The C++ standard doesn't rule the file extension, so the most of people use .cpp, but I prefer using .cc, how to tell Sublime Text save to .cc when using C++ syntax as default?
The way to change the default file extension shown by the save-as dialog when saving a file set to a specific syntax is to override that syntax's default .sublime-syntax file. In your case that would be the C++.sublime-syntax file.
Of course, as MattDMo points out, the easiest thing to do is to manually type the preferred file extension whenever you save a file. But for those that want to make the change, here's how to do it.
Open the Command Palette and select View Package File.
Type C++ and then select C++/C++.sublime-syntax. ST will open the file.
Near the top you should see file_extensions: and a list like this:
file_extensions:
- cpp
- cc
- cp
- cxx
- c++
...snip...
ST uses the 1st item in the file_extensions list as the default file extension for the save-as dialog.
To make .cc the default extension instead of .cpp, edit the list order so that - cc is the 1st item and - cpp is 2nd, i.e. swap the top 2 lines around.
Now save the file in your ST config Packages directory with this path: ../Packages/C++/C++.sublime-syntax. If you like you can create a C++ directory in Packages and then just use Ctrl+S to save because the path will have been automatically set by ST but the file won't save unless the ../Packages/C++/ directory already exists.
Note: The full path on a Linux machine would be like this: /home/user/.config/sublime-text-3/Packages/C++/C++.sublime-syntax
The Package Resource Viewer plugin's Open Resource Command Palette command could be used to extract .sublime-syntax files instead of ST's native View Package File command. That plugin will automatically create the appropriate Packages directory when necessary.
Your altered Packages/C++/C++.sublime-syntax file will now override the default version that is shipped with ST. You can reverse this easily simply by deleting the file. It is safe to delete the directory as well if you are not overriding any other files in the same directory.
The only problem with this is when you install a new version of ST. If the newly installed version has an updated C++.sublime-syntax file, the local one you've created will continue to override the new one. To get around this delete your altered Packages/C++/C++.sublime-syntax file when you install a new version of ST and repeat the steps above to restore your preferred default file extension once the installation has been done.
Unfortunately there is no way around this, you can not partially override the C++.sublime-syntax file with just the file_extensions: section. Of course new versions of ST don't come along very frequently and the C++.sublime-syntax file gets updated even less often. So this is not a major issue.

control+/ does not work to comment multi line in sublime 3

I can't comment out multi line in sublime 3. Looked at this Keyboard shortcut to comment lines in Sublime Text 3 already but it is not fixing it
Sublime version is 3.2.1 build 3207 . on windows 10.
Please help me out if have any tips.
The keyboard binding for commenting is indeed Ctrl+/ (Cmd+/ on MacOS) so in the general case what you're trying should work just fine.
That said, the keys in question are bound to the toggle_comment command and that command requires language specific metadata to know what comments are supposed to look like. For example comments look and work differently in HTML than they do in C or JavaScript. Some file types (such as plain text files) aren't code and thus don't have a concept of comments at all.
If the metadata file for a file type is missing, then the toggle_comment command won't do anything because comments are assumed to not be valid, which seems to be what's happening to here.
The first thing to check would be to examine the bottom right of the window to see if Sublime agrees with you about what the file type is supposed to be. For example, newly created tabs are Plain Text files until you save the file for the first time, and comments are not allowed in Plain Text files.
If the file type doesn't say what you think it should, you can click it to open a menu and select the appropriate type for that file.
If the type of the file looks to be correct and the command still doesn't work, then the metadata file needed is not being provided in the package that is adding support for that language. In that case you should raise an issue with whoever is responsible for the package in question and get them to add the appropriate file.
Based on the comments on your question, you think you're editing JavaScript files but Sublime thinks you're editing an ActionScript file instead. The JavaScript package includes the appropriate file, but the ActionScript package does not.
So in your particular case, your best bet is to switch the file type to JavaScript and your problem should go away. If you actually want to be editing ActionScript instead, then you need to create an issue on the Default package tracker and ask for this to be added.

Can sublime 3.0 convert display from plain text to source color scheme automatically?

I'm little new to Sublime, wanted to know if there is a way to change display in sublime-3.0 from plain text to source colors automatically (i.e. Sublime should keep source colring from where code was copied and pasted like- HTML or XML or Java code) without I changing it manually.
Thanks in Advance!
Sublime Text already does this for some languages, like XML.
It works when you have a blank document that is set to Plain Text format (i.e. you open a new tab), and paste something in whose first line can be identified to be a specific language, using regular expressions.
For XML, it looks for an XML prolog or an XML element with a namespace. Regex
For HTML, it looks for a HTML doctype.
It currently doesn't support Java - I guess it's not easy to come up with a regex that would match only the first line of a Java file and not a C# file, for example. If you do have some ideas, you can use https://packagecontrol.io/packages/PackageResourceViewer to edit the relevant .sublime-syntax (YAML) file and add a first_line_match in.
You may also find the following packages helpful:
https://packagecontrol.io/packages/AutoSetSyntax
https://packagecontrol.io/packages/ApplySyntax
Extra note: these "first line matches" also apply when opening files that aren't automatically matched to a syntax by the file's name/extension.
There might be a better way, but I've done it with the Package control ctrl+shift+p (Win, Linux) or cmd+shift+p (OS X). Search for Package Control: install Package, press Enter and then search whatever package you need.
After installing the SCSS package, I'd get the HTML colouring as well.

Sublimetext file extension annoyance

If I create a brand new sublimetext buffer, then set the syntax of the buffer to something (in this example json).
When I go to save the file, it will have untitled.json in the file save dialog automatically. If I then change that to foo.bar and hit save. The file saved to my filesystem will be foo.bar.json.
Why? My intentions as a user are clear in this case, I'm overriding the file extension for my own reasons.
Is there a way to globally set sublimetext to stop appending what it assumes is the proper extensions to files? Any number of google searches has turned up nothing.

Change SublimeREPL shell colour

I use SublimeText3 and try to change the colour for SublimeREPL Shell because its all white. Is that possible? Or is it possible to use colours from system prompt like PS1='' ?. I am running on ubuntu. I haven't found a soloution.
I assume you're trying to color the prompt in the SublimeREPL shell - if you want syntax highlighting of the commands you type, just change the syntax to Shell Script (Bash). To do this permanently, open your Packages folder (Preferences -> Browse Packages...), browse to SublimeREPL/config/Shell, and open Main.sublime-menu as a JSON file. Line 26 contains the "syntax" setting; just change the value to "Packages/ShellScript/Shell-Unix-Generic.tmLanguage", save the file, and the next time you start it the syntax will be applied.
However, if you're just trying to color the prompt, you'll have much more work to do. First, you'll have to create a custom .tmLanguage syntax definition file creating scopes for the various parts of the prompt you want to highlight, then you'll need to alter your color scheme's .tmTheme file to actually style the scopes. (If you're using the ST3 dev builds and have Build 3084 or newer, you can also use the new YAML-based .sublime-syntax format instead of the XML-based .tmLanguage one.)
If you're not using a dev build, the best way to write syntax definitions is to use the wonderful PackageDev package. I maintain an alternate - and better :) - syntax definition for Python and I much prefer using PackageDev's .YAML-tmLanguage format, which as you can tell is also based on YAML, but was around long before the new "official" .sublime-syntax format, and of course they're incompatible. However, it is quite easy to convert from YAML-tmL to tmL to sub-syn and back again, so it's no big deal.
However, as I was saying, the contents of your syntax definition will vary depending on the exact structure of your prompt, and what you want to do with it. For the following examples, I'm assuming you have the default Ubuntu user#hostname:/present/working/directory$ prompt. To create a new syntax definition, after installing PackageDev, select Tools -> Packages -> Package Development -> New Syntax Definition and you'll get the following:
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Syntax Name
scopeName: source.syntax_name
fileTypes: []
uuid: 7e1549b3-fb0b-44fc-a153-78a7fc2157c2
patterns:
-
...
The first line is required, don't mess with it. You can make name whatever you want. scopeName is obviously the identifier for the base scope, perhaps something like source.shell.prompt. fileTypes can be left blank, and the uuid left alone as well.
If you want to get a feel for how these files are supposed to work, feel free to check out PythonImproved.YAML-tmLanguage on Github, and also make use of the Sublime Text Unofficial Documentation page on the subject as well as the reference. There's also some info in PackageDev's README.
I'll let you develop the rest of the regexes, but here's one for matching the username to get you started:
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Shell Prompt
scopeName: source.shell.prompt
fileTypes: []
uuid: 7e1549b3-fb0b-44fc-a153-78a7fc2157c2
patterns:
- name: meta.username.prompt
match: ^([A-Za-z_][A-Za-z0-9_-]{0,31})(?=#)
...
You can see it working here.
Once your .YAML-tmLanguage is complete, save the file, open the command palette, and select PackageDev: Convert (YAML, JSON, PList) to.... This will build the .tmLanguage file and put it in the same directory as the .YAML-tmLanguage file. If it's not already under the Packages directory tree, copy it to your Packages/User directory, then modify the Main.sublime-menu file as described in the first paragraph. Finally, open your color scheme's .tmTheme file and edit it to add the scopes defined in your new syntax. Save it, restart Sublime for good measure, and you should be all set!

Resources