Here is my Settings - User config:
{
"auto_indent": true,
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"default_line_ending": "LF",
"detect_indentation": true,
"font_size": 10.0,
"ignored_packages":
[
"Vintage"
],
"indent_to_bracket": false,
"smart_indent": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"use_tab_stops": true
}
Comment to default_line_ending option says:
When I create a new file, I check line ending here:
As you can see it's still Windows...
Any ideas?
The comment states
// 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).
You are setting
"default_line_ending": "LF",
You should set
"default_line_ending": "unix",
The EditorConfig project (Github link) is another very viable solution. Similar to sftp-config.json and .sublime-project/workspace sort of file, once you set up a .editorconfig file, either in project folder or in a parent folder, every time you save a file within that directory structure the plugin will automatically apply the settings in the dot file and automate a few different things for you. Some of which are saving Unix-style line endings, adding end-of-file newline, removing whitespace, and adjusting your indent tab/space settings.
QUICK EXAMPLE
Install the EditorConfig plugin in Sublime using Package Control; then place a file named .editorconfig in a parent directory (even your home or the root if you like), with the following content:
[*]
end_of_line = lf
That's it. This setting will automatically apply Unix-style line endings whenever you save a file within that directory structure. You can do more cool stuff, ex. trim unwanted trailing white-spaces or add a trailing newline at the end of each file. For more detail, refer to the example file at https://github.com/sindresorhus/editorconfig-sublime, that is:
# editorconfig.org
root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
The root = true line means that EditorConfig won't look for other .editorconfig files in the upper levels of the directory structure.
to chnage line endings from LF to CRLF:
open Sublime and follow the steps:-
1 press Ctrl+shift+p then install package name line unify endings
then again press Ctrl+shift+p
2 in the blank input box type "Line unify ending "
3 Hit enter twice
Sublime may freeze for sometimes and as a result will change the line endings from LF to CRLF
The simplest way to modify all files of a project at once (batch) is through Line Endings Unify package:
Ctrl+Shift+P type inst + choose Install Package.
Type line end + choose Line Endings Unify.
Once installed, Ctrl+Shift+P + type end + choose Line Endings Unify.
OR (instead of 3.) copy:
{
"keys": ["ctrl+alt+l"],
"command": "line_endings_unify"
},
to the User array (right pane, after the opening [) in Preferences -> KeyBindings + press Ctrl+Alt+L.
As mentioned in another answer:
The Carriage Return (CR) character (0x0D, \r) [...] Early Macintosh operating systems (OS-9 and earlier).
The Line Feed (LF) character (0x0A, \n) [...] UNIX based systems (Linux, Mac OSX)
The End of Line (EOL) sequence (0x0D 0x0A, \r\n) [...] (non-Unix: Windows, Symbian OS).
If you have node_modules, build or other auto-generated folders, delete them before running the package.
When you run the package:
you are asked at the bottom to choose which file extensions to search through a comma separated list (type the only ones you need to speed up the replacements, e.g. js,jsx).
then you are asked which Input line ending to use, e.g. if you need LF type \n.
press ENTER and wait until you see an alert window with LineEndingsUnify Complete.
Related
I would like use sublime for my Mercurial commit messages, so I set
HGEDITOR="C:\Program Files\Sublime Text 3\subl.exe" -w -n a
This will start Sublime with a file named something like hg-editor-mstdne.commit.hg.txt.
Then I would like to be able to have it automatically wrap at 72 characters (like Sublime Text line wrap and commit messages). This can be done per syntax, so I have defined a syntax for it
%YAML 1.2
---
name: hg-commit
file_extensions: [.commit.hg.txt]
scope: text.hg
contexts:
main:
- match: "^HG:.*"
captures:
0: comment.line.hg-commit
I can manually select the syntax, but the commit still opens as Plain Text. If I select View->Syntax->'Open all with current extension as' then all other .txt files are also opened with hg-commit syntax.
Are there any ways to get it to use my syntax for hg commit message files only?
It was pretty simple with the on_load event as #OdatNurd suggested.
import sublime_plugin
# Load special syntax for hg commit. Also sets line wrapping
class RtxOnload(sublime_plugin.EventListener):
def on_load(self, view):
if view.file_name().endswith('.commit.hg.txt'):
view.settings().set('syntax', 'Packages/MLA/hg-commit.sublime-syntax')
view.settings().set('wrap_width', 72)
Only problem is that it only works when Sublime is already running. That could probably be fixed with some other hook, but for me it is not an issue.
RTC (Rational Team Concert) provide a "source control command-line interface (CLI)", where the basic command is 'scm'.
We're currently using version "6.0.2" on Linux (64 bit).
Where a file is added into RTC, it acquires a set of associated properties, such as: jazz.executable, jazz.mime, jazz.read-access, jazz.encoding, jazz.line-delimiter. My primary interest is the "jazz.line-delimiter".
I know that I can modify the default file properties through a "magic.properties" file:
https://www.ibm.com/support/knowledgecenter/SSYMRC_5.0.2/com.ibm.team.scm.doc/topics/t_magicproperties.html
But... what is the default?
I've seen this mentioned, but not really explained, on IBM web help:
If the CLI does not recognize a file type, it is treated as a binary
file
By default, when you share a project or check in a new file, Rational Team Concert™ source control examines the content and sets the line delimiter property of the file to the value PLATFORM.
But... what is the default?
One possible way to see the default for a given file would be to:
not modify those properties through a magic file,
show those properties, as seen in "show properties example"
That is:
scm show prop -r ella abc10.txt
D:\Trash_Testing\Ella\abc5\abc10.txt
jazz.encoding - Cp1252
local.encoding - Cp1252
jazz.executable - false
jazz.line-delimiter - Platform
jazz.mime - text/plain
jazz.read-access - Component scoped
From scm cli on properties:
jazz.line-delimiter
Indicates the line delimiter. May be one of:
platform – Indicates that the file should be given the platform-specific line delimiter on load/accept.
none – Indicates that the file should not have its line delimiters changed on load/accept.
crlf – Indicates that the file should always have Windows-style line delimiters.
lf – Indicates that line-feeds should be used as line delimiters.
cr – Indicates that carriage returns should be used as line delimiters.
When I pres ctrl+shift+F to search across all the files in the current scope, I get a new window listing all the files that contain that search term.
How can I quickly open all of these files?
Hold down the F4 key from the Search Results screen, and it will "Navigate to next match" - which causes it to open each file listed in the results.
Just a small note, if you are getting 10+ matches per file this method starts to fail because it gets slow.
Sublime doesn't have the ability to do this out of the box; however the plugin API gives you the power to create a plugin to do something like this fairly simply (depending on how you ultimately want it to work).
I assume there are plugins available for something like this, but for reference purposes here is a simple example:
import sublime
import sublime_plugin
class OpenAllFoundFilesCommand(sublime_plugin.TextCommand):
def run(self, edit, new_window=False):
# Collect all found filenames
positions = self.view.find_by_selector ("entity.name.filename.find-in-files")
if len(positions) > 0:
# Set up the window to open the files in
if new_window:
sublime.run_command ("new_window")
window = sublime.active_window ()
else:
window = self.view.window ()
# Open each file in the new window
for position in positions:
window.run_command ('open_file', {'file': self.view.substr (position)})
else:
self.view.window ().status_message ("No find results")
This provides a command named open_all_found_files which could be bound to a key, added to a menu, added to the command palette, etc.
Using the notion that sublime has a custom syntax for the find results with a scope dedicated to the matching filenames, this collects all such regions and then opens the associated files.
The optional command argument new_window can be passed and set to true to open the files in a new window; leaving it off or setting it to false opens the files in the same window as the find results. You can of course change the default as you see fit.
You can't do that from within Sublime Text.
If you are using Linux/UNIX/OSX you can open all the files that contain a particular string or matching regex by using a combination of grep and xargs on the command line using a command like this:
grep -rlZ "search_str_or_regex" /path/to/search/* | xargs -0 subl
// Command line options (may vary between OSes):
//
// grep -r Recurse directories
// grep -l Output only the filenames of the files which contain the search pattern
// grep -Z Output null terminated filenames
// xargs -0 Input filenames are null terminated
// xargs subl Sublime Text executable
//
// The combination of -Z and -0 allows filenames containing spaces to be handled
The files will be opened in the most recently used Sublime Text window. Add -n or --new-window after subl to have them opened in a new window.
If you are using Windows, consider using GOW or Cygwin.
I had to change the Code of OdatNurd. I had problems with the ":" and the " " at the end of the Filename... Under Mac OS Big Sur...
import sublime
import sublime_plugin
class OpenAllFoundFilesCommand(sublime_plugin.TextCommand):
"""
Collect the names of all files from a Find in Files result and open them
all at once, optionally in a new window.
"""
def run(self, edit, new_window=False):
# Collect all found filenames
positions = self.view.find_by_selector("entity.name.filename.find-in-files")
if len(positions) > 0:
# Set up the window to open the files in
if new_window:
sublime.run_command("new_window")
window = sublime.active_window()
else:
window = self.view.window()
# Open each file in the new window
for position in positions:
file = self.view.substr (position)
#print(file)
file = file.replace(":","")
window.run_command('open_file', {'file': file.strip()})
else:
self.view.window().status_message("No find results")
def is_enabled(self):
return self.view.match_selector(0, "text.find-in-files")
I am using the latest Sublime Text 3, and have this in a syntax specific config for JavaScript
{
"translateTabsToSpaces": true,
"tabSize": 2
}
But every time I create a new file, it defaults to 4 spaces. I have tried adding "detect_indentation": true but then ALL files started to be 4 spaces for tabs, ignoring the syntax specific config even further.
Am I missing something?
Your settings names are incorrect. Sublime uses snake_case variables, not camelCase. Your JavaScript.sublime-settings file should look like this:
{
"translate_tabs_to_spaces": true,
"tab_size": 2
}
To see all of the available settings, select Preferences → Settings—Default.
A sublime-settings file enforces settings on a per-project basis:
{
"folders": [ ... ]
"settings":
{
"tab_size": 4
}
}
How is it possible to use syntax specific settings in this file, for example to set a tab_size of 2 only for *.js files?
You could checkout .editorconfig.
Basically an .editorconfig file would look like,
# editorconfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
# 4 space indentation
[*.py]
indent_style = space
indent_size = 4
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
There's even a nice Sublime Text package that automatically reads and understands them. Just throw your .editorconfig in version control and you're ready to go.
You can't set language-exclusive settings directly in your user Preferences.sublime-settings file. However, when editing a file of a given type, you can create a settings file limited only to that type with the menu item Preferences -> Settings–More -> Syntax Specific – User.
This new file will appear in your Packages/User directory with a name matching its language, e.g. Markdown.sublime-settings would be a Markdown-specific settings file.