Changing identification settings in Sublime doesn't work for certain existing files - sublimetext3

In my Sublime user settings I have "tab_size": 2, which works great for all new files. But some third party files seem to have their own identification settings embedded into them somehow (in which case my user settings have no effect).
How to overcome them?

The "tab_size" setting is only for new files and existing files that use tabs (instead of spaces) for indentation. If a file uses spaces (which I suspect yours do), Sublime will automatically determine the indentation size. You would need to reindent the file to match your preferred tab size.

Related

set tab-stop = 2 in vim permanently for a file

How to set the tab size as 2 for a file permanently in vim as whenever I open a file in other editors like nano or upload the file in github then my indentations are all incorrent whenever I try to resize the tab to 2 for an existing file which has all incorrect indentations. The tab-stop=2 does not permanently resizes the tab and I see all incorrect indentation when I open the same file in nano or view it in github.
Tabs don't have an inherent size so it is up to each program to decide how to display them and there is simply no way to guarantee that a tab will always look the same everywhere.
This is precisely the main issue people have with tabs: you can tell $SOME_TOOL and $SOME_OTHER_TOOL that a tab takes two spaces but that setting can't possibly be carried over to every tool.
Modelines are editor-specific (and they are too intrusive anyway) and Editorconfig is not universally supported so there is really no universal solution beyond using spaces for indentation.

Sublime keeps using 4-space tab for some files instead of 2-space tab even if I've done all the settings, why and how do I fix?

I'm editing files using Sublime 3.2.2 on my iMac.
I have already set tab-size to 2:
It works for some files but doesn't for some files - remaining 4-sized tabs. I can't even find a clue about which is right and which is not.
Are there any other places I need to check except the settings?
There are two things to consider here. First, this setting (shown here with the default value):
// Set to false to disable detection of tabs vs. spaces on load
"detect_indentation": true,
When this setting is turned on, when a file opens it's examined to try and detect how it;s indented. This will override the tab_size in that particular file with whatever the detected tab size is, and can also override translate_taba_to_spaces as well if the file appears to be indented a particular way.
The setting defaults this way so that you can use your settings to determine how you want to create new files while still allowing you to work with existing files in a sane way; setting it to false turns off this detection.
The second thing to note is that preferences can be set on a per-file-type manner, which also overrides the settings in your user preferences for files of that type.
As an example, YAML files have these settings applied (this is from YAML/YAML.sublime-settings):
{
// YAML mandates that tabs aren't used for indentation
"translate_tabs_to_spaces": true,
// In practice, editing YAML files with anything other than two space
// indentation is tedious, due to the "- " list prefix
"tab_size": 2,
}
So, in a YAML file, regardless of your settings, the tab size defaults to 2 and using spaces over tabs is enforced.
As such, the takeaway here is that if changing the detection setting above doesn't work, check to see if the setting only seems to be "not working" in a particular type of file, and if so you can use Preferences > Settings - Syntax Specific while you have a file of that type open to enforce your settings there.

How can i change indentation settings for flake8 in sublime text?

I am using Sublime Text 3 with the Packet Manager, and installed SublimeLinter and then SublimeLinter-flake8.
I want to use tabs for indentation, but I can't find out how. I can't actually find any indentation that works, because if I put one space it says: flake8: E111 - indentation is not a multiple of four, but when I put four spaces it says: flake8: E101 - indentation contains mixed spaces and tabs.
I am on Windows and using Python 3. Does anyone know how to change the settings?
This is answered in the flake8 documentation:
Flake8 supports storing its configuration in the following places:
Your top-level user directory
In your project in one of setup.cfg, tox.ini, or .flake8.
Values set at the command line have highest priority, then those in the project configuration file, then those in your user directory, and finally there are the defaults. However, there are additional command line options which can alter this.
Since this is editor-agnostic, this should be the favoured approach. Also, you keep flexibility when working with configurations at project-level.
However, you can also specify your flake8 arguments in the SublimeLinter configuration, exactly as described in the documentation for SublimeLinter-flake8. Keep in mind that this is a very unflexible solution since it requires editing if you're using different configuration settings across your projects.

Sublime Text 3: import projects list from folder/files to OpenRecent list

I save several projects in a same folder by manual click Project -> Save Project As...
and I used to use cmd + ctrl + p to open Switch Projectlist to switch between projects
and everything's works fine.
but today, I accidentally remove my Switch Project list in by click Project -> Open Recent -> Clear Items, so my Switch Project list is empty now...
I know I could add them back through reopen ALL my projects. due to the number of projects is pretty a lot, that will be kind of annoying to add them back one by one.
I wanna know if there's a smarter way to do that for me.
maybe import all my *.sublime-project files from folder or something.
thanks
Short of manually opening every project, I don't think there is any way to do something like this directly. There isn't a command or plugin endpoint that I'm aware of that lets you open a project by name or filename, so it's not possible to create a plugin to do the work, and Sublime doesn't have the ability to pre-load the list of packages directly either.
That said, it is possible to manually update the list of recent projects, but whether or not that is more or less work than opening all of the projects is something to consider.
If you use Preferences > Browse Packages from the menu or the command palette, a file browser will open on your Packages folder. From there go up one directory level and go inside of the Local folder, where you will find a Session.sublime_session file.
Sublime saves it's state into this file when you quit it, and uses it to restore state when you start it again. Here you will find all of the saved information, such as the windows and files that were open and so on.
Changing this file will change the data that Sublime loads, so you can modify the session file to set up the data that you want. You need to make sure that you modify the file while Sublime is not running or your changes will be ignored and clobbered away. Also it's a good idea to make a backup of the file before you start in case things go pear shaped.
Down near the bottom of the file you will find a top level key named workspaces, and inside of it a recent_workspaces key:
"workspaces":
{
"recent_workspaces":
[
"/home/tmartin/local/src/OverrideAudit/OverrideAudit.sublime-workspace",
]
}
This is where the list of recent projects is stored for use in the menu and the quick switch project command. Particular things to notice are that the entries are naming sublime-workspace files, and that the paths are absolute.
NOTE: On windows, the filenames stored in the session file are in a format like /C/Users/tmartin and not c:\users\tmartin; on that platform you need to make sure that you adjust the paths accordingly. As long as there is already at least one entry in the list when you look at the session file, you can easily see how to construct the paths that you need.
Despite the name of the commands and menu items, what you're actually switching between is different workspaces. Every sublime-project is associated with a sublime-workspace file, which acts as a dedicated sublime_session file for that particular project. This mapping is one-to-many in that you can have multiple workspaces for the same project file, allowing you to reference the same paths in multiple windows but have different window layouts.
While Sublime is not running you can edit this file to add in the full paths to all of your workspace files; when you start Sublime up the list will be populated (every sublime-workspace file knows what sublime-project it is associated with).
What remains is whether or not it's quick to come up with the list of files in a way that you can easily paste them into the session file.

master config file to set tab=4 spaces for every editor at once

I've had to edit configuration files for all of my various editors (emacs, vim, nano, etc.) to have a tab spacing equal to 4 spaces instead of the seemingly default 8. Is there a more elegant way? Some master file I can point them all to in order to use the same tabs/spaces settings for all of them?
Try to use http://editorconfig.org (you need to place .editorconfig in each project)

Resources