default indentation in sublimetext - sublimetext2

I use Sublime Text and want JavaScript files to use three spaces for indentaiton.
I set this in Packages/User/Preferences.sublime-settings:
{
"tab_size": 3,
"translate_tabs_to_spaces": true
}
but it has no affect and I need to manually change it for each new file.

When you have a JavaScript file open do the following:
Per-syntax Settings
Settings may be specified on a per-syntax basis. You can edit the
settings for the current syntax using the Preferences/Settings -
More/Syntax Specific - User menu.
This will allow you to set custom preferences for the current syntax. More info on indentation here: http://www.sublimetext.com/docs/2/indentation.html

Related

vscode text editor settings - manually configure language list

I would like to auto-close brackets for .csv files when they are open in vscode. Given the following user settings...
{
"editor.autoSurround": "languageDefined"
...
"editor.autoClosingQuotes": "languageDefined"
}
... is there a user configuration where I can add or remove language modes to apply the autoClosingQuotes setting(s) to without enabling it for all language modes?
What you want are called "language-specific settings". See using language-specific settings in vscode and documentation for same.
In your case:
"editor.autoClosingBrackets": "never",
"[plaintext]": {
"editor.autoClosingQuotes": "languageDefined"
}
You can play with those settings to achieve what you want. First I set all languages to never, and then enable it only for plaintext.
Why did I use [plaintext] above? Because in looking through the choices (Ctrl-Shift-P and search for "configure language-specific settings" there isn't a .csv choice. I assume plain text is as close as you are going to get.

Sublime text 2 Snippets - autocomplete

I've created a bunch of snippets in Sublime Text 2, but I cant remember them all off the top of my head. I've seen in a number of tutorials that as people start typing their snippets tab-triggers it will start to provide a list of the matching snippets. I don't see this.
Is there a setting somewhere for this? Or do I need to create a special file (completions file?). For most snippets I have the <scope> commented out as I may use in a PHP or HTML file for example depending what I am working on.
Most of my snippets tab triggers start the same elq- prefix, so it would be very helpful if it were to start showing me the options as I type.
The setting auto_complete_selector controls when Sublime automatically offers the popup for possible completions. The default value for this setting is:
// Controls what scopes auto complete will be triggered in
"auto_complete_selector": "source - comment",
This means that it will automatically pop up for any file that's considered a source code file, except within a comment.
The scopes for the file types that you mention in your question are text scopes and not source scopes, which stops the popup from appearing.
One way around that would be to manually invoke the auto complete panel by using the appropriate key binding, which by default is Alt+/ on Linux or Ctrl+Space on Windows/OSX. When you do that, the popup for possible completions at this point is manually displayed.
To allow this to work more automatically, you would need to modify the setting for auto_complete_selector to be more appropriate for your situation.
To do that you could select Preferences > Settings - User from the menu and add or modify the auto_complete_selector setting as follows:
"auto_complete_selector": "source - comment, text.html",
This says that the selector should always be displayed in source files except inside comments (like the default) and also within HTML files.
You could also use text instead of text.html if you want it to work in all text files of all types, although this would possibly get quite annoying while working with plain text files. Substitute an appropriate scope or set of scopes here as appropriate to dial in the places you want this to be automatically offered.

Setting tab size/ space size as default in VSCode

I'm currently using VSCode and I have this problem. I want to set the space size equals to 1 and tab size equals to 2 as default for every project. But it still set back as spaces: 4 for every project.
And as I set the spaces = 2, and run Beautify file. Everything looks good with space = 2. Then I hit save it format my file to indent size 4. How do I set it as default equal to 2 guys?
even I change in User settings
By default VSCode try to detect indent option for a file. So set editor.detectIndentation to false
// When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
"editor.detectIndentation": false,
EditorConfig is a handy standard for establishing project wide formatting options: http://editorconfig.org.
There's a VSCode extension supporting it: https://github.com/editorconfig/editorconfig-vscode
This doesn't directly answer your question, but it works well. And if you switch editors, you still can keep your formatting standard by getting each editor's plug-in for EditorConfig.

How to configure Sublime text to support both spaces and tabs for indentation

I am using Sublime Text for JavaScript development where I use tabs for indentation.
But, for Python development, I need to use spaces (per PEP-8). So what config directives should I change to support both.
(I am fairly new to Sublime Text)
You can create syntax specific configurations. Preferences -> Settings - More ->Syntax Specific - User. Add the following configuration "translate_tabs_to_spaces": false, setting the boolean as appropriate.

Sublime Text 2 tab_size setting not correctly activated

I have the following in my user/Preferences.sublime-settings
{
"tab_size": 2,
}
And most of the time it works. But once in a while I open a ruby file, and it jumped back to 4 spaces. I'm wondering if there is some bug or slight difference in opening a file that could change this?
Having trouble tracking this down. Thanks for the help.
You'll want to add:
"detect_indentation": false
This is on by default and ST is trying to be smart detecting the indentation of your current file, overloading the user or syntax specific default.
Here are various Sublime Text 2 tab settings explained:
http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Configure_sane_tab_and_whitespace_policy_and_other_settings
Note that the tab setting may be per file type
There is also autodetect from file enabled by default and your source code file may contain bad tabbing