Changing default syntax based on filename - sublimetext2

In Sublime Text 2, I've seen ways of basing the syntax off of the extension. But what about a filename with no extension? For example, I often have a file called "Vagrantfile" which is in ruby, yet Sublime Text 2 always wants to start off in plain text. Is there a way to have it default to "ruby" for a file if it is called "Vagrantfile"?

With Sublime Text 2.0.1, build 2217, look in the lower right of the window, where it says "Plain Text" for the Vagrantfile that is open.
Click that and in the menu that opens, at the top, there will be an "Open all with current extension as ..." sub-menu. Go into that sub-menu and choose Ruby.
Even though the Vagrantfile has no extension, Sublime will remember this and open Vagrantfiles with the Ruby syntax as expected. This does not spread to all files with no extension.

Add the following line to the Syntax Specific - User file in
Preferences > Setting - More > Syntax Specific - User
for permanent staying of the syntax for every Vagrantfile file.
{
"extensions":
[
"Vagrantfile"
]
}

Related

apply syntax highlighting to files with undefined extension

I'm opening .RUL files in Sublime Text which do not have any syntax highlighting, since InstallScript has a similar syntax to C/C++ I want all my .rul files to be treated as if they were .c or .cpp files and automatically have all the same highlighting applied to them. In other words: I want to have the same effect as if I renamed each .rul file to .cpp and then opened the .cpp in Sublime.
What's the easiest way to implement this in Sublime Text 2.0.2 ?
You can open the file in Sublime Text and use menu "View" → "Syntax" → "Open all with current extension as..." → (select appropriate syntax).
Also, you can click on right bottom corner of the window. This will open similar menu, where "Open all with current extension as..." is presented too.
I'm not sure if the other solutions posted above will apply to all future instances of *.rul files, OR only to the currently open file.
I found a solution that works perfectly fine for me, just edit:
...\Application Data\Sublime Text 2\Packages\C++\C.tmLanguage
<key>fileTypes</key>
<array>
<string>c</string>
<string>h</string>
<string>rul</string>
According to:
http://docs.sublimetext.info/en/sublime-text-2/reference/syntaxdefs.html
fileTypes
This is a list of file extensions (without the leading dot). When opening files of these types, Sublime Text will automatically activate this syntax definition for them. Optional.
Press Ctrl+Shift+P and type C++, highlight Set Syntax: C++ and press Enter.
Or go to View menu > Syntax > Click C++.
/Users/HOME/Library/Application Support/Sublime Text 2/Packages/C++/C++.sublime-settings
{
"extensions": ["cpp", "cc", "cxx", "c++", "h", "hpp", "hxx", "h++", "inl", "ipp", "rul"]
}
Or, create a similar file and place it in your User directory, for rul and any other additional extensions not defined in the file mentioned hereinabove:
/Users/HOME/Library/Application Support/Sublime Text 2/Packages/User/C++.sublime-settings
{
"extensions": ["rul"]
}

Sublime Text 2 highlighting always disabled on trailing spaces plugin

In Sublime Text 2 I have installed the trailing spaces plugin, however the highlighting is always set to disabled.
if I toggle the highlight regions, by doing the following:
edit -> trailing spaces -> highlight regions
I always get the following:
highlighting of trailing spaces is disabled!
I have restarted sublime since the package install, but the toggle doesn't seem to work, does anyone know how to fix this issue?
Work around fix - not the solution to the problem
As for others it seems, i couldn't seem to get this trailing spaces to highlight no matter what i did, so what i did was remove the trailing spaces automatically on save. Not ideal but used to it now, works nicely.
Go to SublimeText 2 > Preferences > User Settings (or just hit the Mac Standard cmd + ,). This should open your User Settings as a JSON file. Add the following to your file
"trim_trailing_white_space_on_save": true
That's it. You're good to go.
I had this problem in Sublime Text 3.
I fixed it by deleting my trailing_spaces.sublime-settings file in the Sublime Text user package settings folder (which for me was %APPDATA%\Sublime Text 3\Packages\User) and reinstalling the plugin.
Some more discussion about this issue can be found on the plugin GitHub page here.
It's a known bug - see their Issues page on GitHub.
I was able to get it working by starting Sublime with a non-blank string value for the setting trailing_spaces_highlight_color
Open Preferences > Package Settings > Trailing Spaces > Settings - User
Replace:
"trailing_spaces_highlight_color": ""
With:
"trailing_spaces_highlight_color": "invalid"
Restart Sublime.
Edit > Trailing Spaces > Highlight Regions should work as expected now.
If you restart Sublime, "trailing_spaces_highlight_color" must not be a blank string, otherwise it will stop working again. Repeat the steps above to fix.
As long as Sublime is started with a non-blank string value for trailing_spaces_highlight_color, the toggle highlight regions works.
It looks like the plugin is caching the value in the setting file when Sublime loads. If you make changes to the settings file and toggle highlighting, the original value is restored. Which is why you need to restart Sublime for setting changes to take effect.

Different rulers by file type in Sublime Text 2

Is there a way to tell sublime text 2 to display a column 78 ruler in python and javascript and no ruler in HTML, by default?
Yes! For both a Python and a Javascript file, open it (or just set the syntax for an empty file to Python or Javascript), then click Preferences -> Settings – More -> Syntax Specific – User. Edit that settings file like you would your regular user settings file. Once you're finished, it will look something like this:
{
"rulers": [
78
]
}
Do the same for HTML, but make the "rulers" array empty, i.e.:
{
"rulers": [ ]
}
Subsequently, Javascript and Python files will have a ruler at line 78, whereas HTML will display no rulers. Any settings that you can define in your user settings file can be made specific to a syntax.
Close the file and re-open it if it doesn't take effect. Had to do this with my .py files. Applies for Sublime 3

Open/Close braces / brackets : highlight the lines that connect them in Sublime

I miss a nice feature of Notepad++ which was connecting the opening and closing line of a function/bracket with a highlighted line. Sublime connects them too, but the dotted line doesn't change color...
Take a look at BracketHighlighter. With a little configuration, I think it will give you what you want. Specifically the Configuring Highlighting Style section.
Steps after installing BracketHighlighter...
From Preferences -> Browse Packages... create a file called bh_core.sublime-settings in your User folder.
Add the following code:
{
"content_highlight_bar": true,
"align_content_highlight_bar": true,
}
Here is the section you are looking for!

Set Default Syntax for a New Created File in Sublime Text 2

In Sublime Text 2, when I double-click on the tab bar, it will create a new file, Sublime Text 2 will give it Plain Text syntax, How to change this default Plain Text syntax to HTML syntax?
I know there is a sublime-DefaultFileType that could set the default file type of new files which are created with the Ctrl+N. However, how can I make it take effect when I double-click on the tab bar to create a new file?
I'm afraid there isn't a solution for double click.
According to the official website, DefaultFileType
This only affects files which are created with the Ctrl+N shortcut (Cmd+N on OSX).
for installation, follow the Installation part.
Please refer to this stack post: (On Text 3 it also works fine)
Sublime Text 2 Default File Type on new file
This py code solution support double click. DefaultFileType might be an easy option. But it didn't work in some cases, it has been 5 years old. In fact, I have to use this method for text 3 on windows.
This is the syntax for SQL :
http://rouge.jneen.net/pastes/PNq0
save it like DefaultLanguage.py
use the default location : \Data\Packages\User