Sublime Text 2 loading all shell scripts as plain text [duplicate] - bash

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?

In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...

I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.

I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).

For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )

There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.

There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.

I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

Related

How to define 'previous file' and 'next file' shortcut keys in Sublime Text 3?

I'm trying to implement 'Next File' and 'Previous File' shortcuts in Sublime Text 3 following this answer, Change "Next File" and "Previous File" shortcut in Sublime Text 2.
However, I'm unable to find the "Key Bindings - User" file mentioned in that answer. I can find some .sublime-keymap files in ~/Library/Application Support/Sublime Text 3/Packages, but they seem to be specific to certain installed packages:
~/L/A/S/Packages> find . -name '*keymap*'
./pymdownx/st3/pymdownx/keymap_db.py
./Pretty JSON/Default (Windows).sublime-keymap
./Pretty JSON/Default (OSX).sublime-keymap
./Pretty JSON/Default (Linux).sublime-keymap
./Babel/Default.sublime-keymap
Where would be the right place to add these commands?
[
{ "keys": ["ctrl+]"], "command": "next_view" },
{ "keys": ["ctrl+["], "command": "prev_view" }
]
Incidentally, the next_view and prev_view commands are described at https://docs.sublimetext.io/reference/commands.html.
See the answer I added in your other question regarding why you can't find the files that the documentation is pointing to.
Regarding how many of the resource files in Sublime Text work, when Sublime loads them it gathers all of the files with the same name across all of the packages you have installed and combines them together. This merging happens in a very specific order related to the name of the package that the files are in to ensure consistent results. Generally speaking, the package list is sorted lexically by name and files are merged in that order, except that Default always comes first and User always comes last.
This allows Sublime to provide the default bindings in the Default package, any package can include their own bindings that augment the list, and the User package (where all of your user specific customizations go) is the "final arbiter".
In this case, the default key bindings for your platform are stored in the Default (<platform>).sublime-keymap file in the Default package, and your user customized key bindings are in a file of the same name in your User package.
The Preferences > Key Bindings menu item opens the appropriate files in a split window, with the platform defaults on the left and your user customizations (if any) on the right.
It's also worth noting that in previous versions of Sublime Text, the menu items for editing things such as key bindings existed as multiple items, so you would see things like Preferences > Key Bindings - Default and Preferences > Key Bindings - User. In this case, one menu item opens the defaults for your platform and the other opens your user file.
Some packages still present their settings in this manner and some have switched to the new format, so this is still something that you see from time to time. In cases like this, you can pick the single menu item to refer to either of the older style menu items. It's essentially doing both of them for you at the same time.

How do you set the default file extension for a syntax in Sublime Text 3?

I'm not asking about associating a syntax with a file extension, but about associating a file extension with a syntax. That is, setting the file extension suggested in the save file dialog after you create a new file, then set the syntax, then hit save.
You can change the extension in the save dialog, but it would be better not to have to do that every time.
For saving plain text files with a .txt extension by default, you can achieve this with a small plugin:
import sublime
import sublime_plugin
class DefaultPlainTextExtensionEventListener(sublime_plugin.EventListener):
def update_default_extension(self, view, syntax):
if syntax == 'Packages/Text/Plain text.tmLanguage':
view.settings().set('default_extension', 'txt')
elif view.settings().get('default_extension', None) == 'txt':
view.settings().erase('default_extension')
def on_new_async(self, view):
self.update_default_extension(view, view.settings().get('syntax'))
def on_post_text_command(self, view, command_name, args):
if command_name == 'set_file_type':
self.update_default_extension(view, args['syntax'])
elif command_name in ('paste', 'paste_and_indent'):
self.update_default_extension(view, view.settings().get('syntax'))
Note that we can't use the on_pre_save event because the file dialog has already been shown to the user by the point this is triggered, and the file name chosen.
The idea is that, when a new tab is created or the syntax is changed to Plain Text, it will set the default_extension setting to txt. If the syntax changes to something else, it will remove the default_extension.
For changing the default file extension for a syntax, it requires changing the .sublime-syntax file to re-order the file extensions set, so that the default one is first in the list.
(Using the default_extension referenced earlier is unreliable.)
So, for Markdown, you could do the following to change the default from .mdown to .md:
Install PackageResourceViewer if it is not already installed
Open the Command Palette
Type PRV: O
Select PackageResourceViewer: Open Resource
Select Markdown
Select Markdown.sublime-syntax
Find where it says:
file_extensions:
- mdown
- markdown
- markdn
- md
Change it so that md is at the top:
file_extensions:
- md
- mdown
- markdown
- markdn
Save the file
Then, when you create a new tab, set the syntax to Markdown and save it, it will default to the .md file extension.
Note that you could try to create an issue/PR at the relevant GitHub repo, if you believe that changing the default could benefit others too and want to see the repo maintainer's reaction.
Are you also trying to set, say, .txt. as the default file extension for when saving plaintext documents? I've looked around and as far as I've seen it's not currently possible to do so. Sadly the default Plain Text content type appears to be the only one that DOESN'T default to its specific .txt extension even though it exists in the Save as type dropdown in the Save As window:
I've seen the AdvancedNewFile plugin recommended as a way to work around this but I don't have any personal experience with it.

Sublime Text 2 - Autocomplete questions

I'm loving Sublime text but there are a few things I'd like to configure on the auto-complete:
HTML: Auto-completion of attributes within tags
When adding a class attribute to a div I have to do control+space to get the auto-complete list, is there a way of bringing that up automatically when adding attributes to tags?
HTML: Adding equals and quotes
When auto-completing the class attribute I then have to type the equals and quotes, can they be added automatically?
CSS: Auto-completion of property values
When I autocomplete a property, e.g. position I then have to add a space and press control+space or start typing to get the values autocomplete list. Is there a way of showing this list straight after the property autocomplete?
I've tried searching for an existing solution but can't find one, so I'm hoping there are some config files that I can amend! Any help pointing me in the right direction would be greatly appreciated! Thanks!
Darren
Try control + shift + p -> set syntax HTML in order to get auto-completion on html tags
also install: http://wbond.net/sublime_packages/package_control (streamlines package installation process)
and emmet: https://github.com/sergeche/emmet-sublime (makes writing html/css x times faster)
for more information on configuring sublime text you could check:
http://net.tutsplus.com/tutorials/tools-and-tips/sublime-text-2-tips-and-tricks/
and
http://net.tutsplus.com/articles/news/perfect-workflow-in-sublime-text-free-course/
Definitively for autocompletion install first Package Control and them Emmet from the Palette Command, just search "emmet" and Enter.
If you don't have Package Control installed, do that first. Next find the Tag package through Package Control via ST2 and install it. I believe that's the one you're looking for, otherwise Emmet (Zen Coding) could be the one I'm thinking of. Either way, make sure your document syntax is set to HTML.

Assign code snippet to keyboard shortcut in Visual Studio

Anyone knows how to assign key shortcut to specific code snippet?
I would like to assign for instance CTRL+K,CTRL+J to a #region snippet.
Therefore by able to:
select text,
press CTRL+K,CTRL+J =>
selected text would be surrounded with #region .. #endregion.
I hate when I have to take my hands out of keyboard for more time than necessary:).
EDIT: For more understanding, I am asking how to bind key shortcut directly to SPECIFIC snippet. Opening snippet selector wont work for me. If I have to search through all my snippets to get to a the #region one, its worse then writting all its code by myself.
Thx for any suggestions.
Type a < and then type your snippet shorcut(your XML file Name) and then press tab.
you can get more info from this link
https://learn.microsoft.com/en-us/visualstudio/xml-tools/how-to-use-xml-snippets?view=vs-2017
for example i have a code snippet which i've set xml file name and its shortcut to flog
when i want to use it directly to my code i do like this:
<flog and press tab it Works.
The closest solution I've found for this is to copy the intended snippet to your local snippets directory.
e.g. For VS-2015:
%Userprofile%\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets
Then open it in a text editor and change the shortcut to something quick and simple such as '1'.
Now to use it, all you need to do is press Ctrl+K+S > Enter > 1 > Enter
Additionally, you can make it even quicker by changing the hotkey for the surround-with command.
(Tools > Options > Keyboard > Edit.SurroundWith)
I think you may want to try adding a <Shortcut> tag inside your MySnippet.snippet file
<Header>
<Title>Square Root</Title>
<Author>Myself</Author>
<Description>Calculates the square root of 16.</Description>
<Shortcut>sqrt</Shortcut>
</Header>
For details check out : https://learn.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet?view=vs-2019#description-and-shortcut-fields
To add a shortcut, add a Shortcut element within the Header element
For me the fastest solution was to Import a Folder named "1", then Add the snippet (my name was "block") and mark it in the 1-Folder.
Then i can insert the snippet by
<Ctrl+K,X> + <Enter> + <Enter>
First Enter chooses 1 (the Folder with MY snippets) and the second Enter chooses my most used snippet (must be alphabetically first)

How to customise file type to syntax associations in Sublime Text?

I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage
And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:
<dict>
<key>bundleUUID</key>
<string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
<key>fileTypes</key>
<array>
<string>scala</string>
<string>sbt</string>
<array>
...
PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
I put my customized changes in the User package:
*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage
Which also means it's in JSON format:
{
"extensions":
[
"sbt"
]
}
This is the same place the
View -> Syntax -> Open all with current extension as ...
menu item adds it (creating the file if it doesn't exist).
For ST3
$language = "language u wish"
If exists, open ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
{
"extensions":
[
"*yourextension*"
]
}
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box
ss + (which type you want set)
eg: ss html +Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
Type "SCALA"/"scala" and press Enter
Type Scala.sublime-syntax and press Enter and press Esc to close the
open list
Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
Save and close the file and restart Sublime Text, you'll now have
Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.
Pretty easy to follow, right ?

Resources