How do configure Sublime Text to always convert to Unix line endings on save? - sublimetext3

I want all files that I ever save in Sublime Text to be in Unix line ending format, even when I open files that were originally saved in a different format that I later edited in Sublime Text?
Simply setting "default_line_ending": "unix" is not enough, because that doesn't convert Windows files as I mentioned. How do I do that?

In SublimeText3 (possibly other versions) you can define this in your User Preferences.
On the menu bar open "Preferences -> Settings"
In the right window pane that opens you will find you are editing "Preferences.sublime-settings -- User". In that pane enter the following JSON formatted options:
{
// Determines what character(s) are used to terminate each line in new files.
// Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
// 'unix' (LF only).
"default_line_ending": "unix",
// Display file encoding in the status bar
"show_encoding": true,
// Display line endings in the status bar
"show_line_endings": true
}
NOTE: I added a couple extra features here. One to tell you what format of file you are working with and that files encoding format. These will appear in the tool bar in the bottom of your ST3 application.

Here's a quick plugin to do the job:
import sublime_plugin
class SetUnixLineEndingsCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.set_line_endings("unix")
class SetLineEndings(sublime_plugin.EventListener):
def on_pre_save(self, view):
view.run_command("set_unix_line_endings")
In Sublime, select Tools → Developer → New Plugin…. In the window that opens, delete everything that's there and replace it with the program above. Hit Save, and the save file dialog should open in your Packages/User directory, whose location varies by OS and type of install:
Linux: ~/.config/sublime-text-3/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages
Save the file as set_unix_line_endings.py and it will activate immediately.
The plugin will only change the line endings of a file if you edit the contents and then save it. Just opening a file to view won't change anything.
If you no longer want the plugin active, just enter your Packages/User directory and either delete the file or change its suffix to something other than .py - set_unix_line_endings.py.bak works well for me.

Related

Cmd + S of TeX file in Sublime Text turns off spell check [MacOS] [duplicate]

This question already has an answer here:
Sublime Text - spell check but only certain file extensions
(1 answer)
Closed 4 days ago.
Problem
I have been experiencing this weird effect where every time I press Cmd+s to save a .tex file, the spell check gets disabled.
I tried ...
This bug is not there in other file types (tested on .txt, .py, .bib, .nml)
Builds
I use Sublime Text build 4143 on MacOS Monterey 12.6.3. and I edit .tex files to build documents using the Sublime package called LaTeXing 1.4.0.
Any hints are appreciated.
The procedure in the link pointed out in the comments by #Parthis worked for me.
In short:
Open a .tex file (or whichever file you want to keep the spell check on).
Go to Preferences > Settings - Syntax Specific. This will open a settings file specific to .tex. Mine was blank with only { }.
Add "spell_check": true between the { }
Now my spellcheck is not affected by Cmd+s anymore!

How to configure Sublime Text 3 editor settings for specific file extensions?

I want to change some editor settings that's only applicable to certain file extensions.
As a test I created 2 files with these contents (in essence overriding what I have as default):
> cat Preferences.sublime-settings
{
"tab_size": 2,
"translate_tabs_to_spaces": true
}
> cat Powershell.sublime-settings
{
"tab_size": 12,
"translate_tabs_to_spaces": true
}
> cat Ps1.sublime-settings
{
"tab_size": 12,
"translate_tabs_to_spaces": true
}
I closed and reopened Sublime Text and pressing the tab key still produces 2 spaces for tabs instead of 12.
Any ideas on how to make it work? Thank you.
This answer assumes you have already installed and been trying to configure the PowerShell package from Package Control.
The reason your settings are not working is because the settings' file names that you tried are wrong. The PowerShell package uses the file name PowershellSyntax.sublime-settings for its settings, that is what you need to use.
Most packages use their package name as the file name for their .sublime-settings file but clearly not all do. In this case there is a much older PowerShell package called stposh which already made use of the file name PowerShell.sublime-settings so, in all probability, the developer of the newer PowerShell package was forced to choose a different file name to avoid a conflict. Clearly the choice of PowershellSyntax.sublime-settings made setting up the package less intuitive, in my opinion the settings file name should be mentioned in the package's README.
// Save as 'PowershellSyntax.sublime-settings'
// in your Sublime Text config 'User' folder.
{
// 8 or even just 2 is probably better to test with
// but stick with the massive 12 if you want to. :)
"tab_size": 12,
"translate_tabs_to_spaces": true
}
In future if a .sublime-settings file does not work, look on the package's homepage which is always linked from Package Control. A browse through the source file names will usually quickly reveal the correct settings file name to use. If the package is already installed, you could also open its .sublime-package file, which is a zip archive, these are stored in the Installed Packages folder.
Some Extra Hints:
The PowerShell Package should automatically recognise the following file extensions .ps1, .psm1, .psd1 and use its syntax when they are opened. To force another file extension to automatically use that syntax, e.g. .ps, click on the currently active syntax name on the far right of the status bar, a context menu will be shown, hover the mouse pointer over Open all with current extension as..., and then select PowerShell from the list.
To manually instruct Sublime Text to convert tabs to spaces, or vise versa, click on where it says either Spaces: n or Tab Size: n on the status bar, doing so will open a context menu. You can then switch between spaces and tab indentation by selecting or unselecting Indent Using Spaces. Open the same context menu again and select whichever conversion is then required from the bottom 2 menu items. This last stage can also be performed by typing indentation into the Command Palette and choosing from the self-explanatory options.

Default folder missing in Sublime Text 3 directory

After installing Sublime Text 3, I try to use a custom keyboard shortcut (F5) defined in:
~/.config/sublime-text-3/Packages/User/Default (Linux).sublime-keymap
The shortcut doesn't work, and I see in the console the following message:
Unable to open /home/gabriel/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings
Not only this file is missing in ST's install directory, the entire ~/.config/sublime-text-3/Packages/Default/ folder is missing. But If I open Preferences/Key Bindings, the default keymap file is opened correctly:
and the path shown for that file is within the ~/.config/sublime-text-3/Packages/Default/ folder, which I know is not there (!)
What is going on here? How can I fix this?
Why the Key Binding is not working is nothing to do with the default file paths, the directory not existing, or the console errors.
Restart Sublime Text and the Key Binding will work. Enable command logging to see that it's working: in the console sublime.log_commands(True).
Sublime text shouldn't be displaying the paths for those Default package files. The ~/.config/sublime-text-3/Packages/Default/ directory doesn't exist because those files are distributed with Sublime Text, you'll find the files in the the Default package where Sublime Text is installed e.g. /path/to/sublime_text_3/Packages/Default.sublime-package. .sublime-package files are essentially zip files. Ignore those paths, and the error messages in the console. Those are Sublime Text issues.
None of these answers are directly solving the problem you nerds.
For the silicon-challenged, what you need to do is this:
go to the path that it's telling you doesn't exist:
/home/gabriel/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings
You are on the right track to deducing the source of the problem - I have the same problem but It wouldn't allow me to change the font for my text editing. Sublime must have an install problem. I'm on ubuntu 16.04 LTS .
Do this:
a. create the folder, name it "Default" - under "Packages"
b. go to your sublime text and go to preferences -> settings
c. copy everything on the LEFT side (it should be showing a full list of defaults, which you can't edit, and a user changeable file on the right)
d. go to the folder you just made (Default) -> inside it create a file with the exact name "Preferences.sublime-settings"
e. paste everything into it
f. restart sublime text
g. You are now a G
you're welcome
I arrived here via a very similar search for why a directory was not being displayed in sublime text. In case anyone else arrives here from the same search, here's why:
directories that are known to house source control information and various binary output files are automatically excluded from the sidebar
Source: https://forum.sublimetext.com/t/missing-files-in-folder-tree/31145/3

How do I set sublime text to auto detect a file type after setting it once?

for instance I have a .zsh file that I would like to always open in sublime as a "Shell Script (bash)" file type. Currently it defaults back to a text file format even when I change and reopen it.
Look in the bottom right of the window.
Click the file type name. Let's assume it is 'Shell Script (Bash)'.
Notice that the first option is 'Open all with current extension as...'
Follow the obvious steps from there and you should be all set.

How do I get gvim/vim to open a file in a path with non-ascii characters?

At first I had this path to one of my files in Windows:
C:\mine\NOTES
I renamed it such that the last part of the path i.e 'NOTES' had the U+2588 FULL BLOCK=solid
before and after it. I inserted the character using the key combination ALT+219(alt code) which is an extended ascii drawing character. I did this so that the folder could stand out from the 20 plus folders in the directory. At this point, I'm quite happy that it looks cool and does stand out. However, when the files in the folder using a text editor all hell breaks loose. These are the results when I try to open the file scheme_notes.scm in different editors:
path="C:\mine\&#brevbar NOTES &#brevbar"
(The solid character is rendered as a &#brevbar character instead of a solid block.
GVIM prints:
"path" [New directory]`
"path" E212: Can't open file for writing.
Python(IDLE) opens the file but does not display the contents which the file has and prints the following error when you try to run it(I know it's not a python file, I was testing)
IOError: [Errno 2] No such file or directory: 'C:\\mine\\\xa6 NOTES \xa6\\python_notes.py'
(The \xa6 is a &#brevbar character)
Pspad does not allow you to edit the file:
File has set attributes: Hidden ReadOnly System
Save Changes Made to File?`
Scite displays a dialog saying:
Cannot save under this name. Save under different name?
If you click yes, the dialog keeps popping up repeatedly. I had to kill the program using
powershell after there were 15 plus dialogs on the window.(and it hadn't stopped)
Jedit prints:
The following I/O operation could not be completed:
Cannot save: "path" (The system cannot find the path specified)
Netbeans:
Failed to set current directory to "path" The system cannot find the file
specified.
I want Vim to be able to open the file without resorting to renaming the folder. Does vim have a setting for opening paths with unicode characters?
I'm asking this because python was able to change to that directory when I did this:
import os
os.chdir(u"\u2588 NOTES \u2588")
os.listdir('.')`<br> `==> ['scheme_notes.scm','python_struff.py']

Resources