Here is an example of what is happening now:
.class {
}
So when I'm typing .class { SublimeText automatically inserts } (which is correct).
Then I press Enter and get this:
.class {
#CURSOR_POSITION#
}
But what I really want is (attention to the closing bracket):
.class {
#CURSOR_POSITION#
}
I've even seen (ok, it was only once) in some editor special setting for this. Now I start using SublimeText (which is cool!) and I feel that it can be customized in a such way but I'm not quite sure how.
Ok! It's not really hard to do it but it was not simple to know how to do it =)
So my approach is:
Write a simple macro (I've edited the default Enter macro called Add Line in Braces.sublime-macro which lives in ~Data/Packages/Default) and save it with a new name.
I've called it CSS.Add Line in Braces.sublime-macro and put in ~Data/Packages/User.
[
{"command": "insert", "args": {"characters": "\n\n"} },
{"command": "move_to", "args": {"to": "hardbol", "extend": false} },
{"command": "insert", "args": {"characters": "\t"} },
{"command": "move", "args": {"by": "lines", "forward": false} },
{"command": "move_to", "args": {"to": "hardeol", "extend": false} },
{"command": "reindent", "args": {"single_line": true} }
]
Apply it for Enter key in CSS files. For that we need to fo to Preferences > Key Bindings - User (it will open ~Data/Packages/User/Default (YOUR_OPERATING_SYSTEM).sublime-keymap) and paste there the following code:
[
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "Packages/User/CSS.Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.css" },
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
}
]
It is copy-pasted from the defult keybinding file with one context addition:
{ "key": "selector", "operator": "equal", "operand": "source.css" }
which tells Sublime to apply it only for CSS ext.
Profit!
Related
This is a follow up question to an already solved one.
For this previous question an answer was given, how to define a cursor for query-pagination with 'startAt' for REST, that relates to a range of documents. In the example below, the cursor relates to all documents with an 'instructionNumber.stringValue' equal to "instr. 101". According to my testing, this results in skipping of documents.
New question:
How has the cursor to be defined, to not only relate to the stringValue of a field, that the query is ordered by? But instead to a distinct document (usually defined by its document-id)?
"structuredQuery": {
"from": [{"collectionId": "instructions"}],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "belongsToDepartementID"
},
"op": "EQUAL",
"value": {
"stringValue": "toplevel-document-id"
}
}
},
"orderBy": [
{
"field": {
"fieldPath": "instructionNumber"
},
"direction": "ASCENDING"
}
],
"startAt": {
"values": [{
"stringValue": "instr. 101"
}]
},
"limit": 5
}
}
For better understanding, here is the condensed schema of the documents.
{
"document": {
"name": "projects/PROJECT_NAME/databases/(default)/documents/organizations/testManyInstructions/instructions/i104",
"fields":
"belongsToDepartementID": {
"stringValue": "toplevel-document-id"
},
"instructionNumber": {
"stringValue": "instr. 104"
},
"instructionTitle": {
"stringValue": "dummy Title104"
},
"instructionCurrentRevision": {
"stringValue": "A"
}
},
"createTime": "2022-02-18T13:55:47.300271Z",
"updateTime": "2022-02-18T13:55:47.300271Z"
}
}
For a query with no ordering:
"orderBy": [{
"direction": "ASCENDING",
"field": {"fieldPath": "__name__"}
}],
"startAt": {
"before": false,
"values": [{"referenceValue": "last/doc/ref"}]
}
For a query with ordering:
"orderBy": [
{
"direction": "DESCENDING",
"field": {"fieldPath": "instructionNumber"}
},
{
"direction": "DESCENDING",
"field": {"fieldPath": "__name__"}
}
],
"startAt":
{
"before": false,
"values": [
{"stringValue": "instr. 101"},
{"referenceValue": "last/doc/ref"}
]
}
Be sure to use the same direction for __name__ as the previous "orderBy" or it will need a composite index.
To ensure you have identify unique document for starting at you'll always want to include the document ID in your call to startAt.
I'm not sure of the exact syntax for the REST API, but the Firebase SDKs automatically pass this document ID when you call startAt with a DocumentSnapshot.
When creating a new CSS rule, I would like the closing bracket to be placed automatically right under the class name, so as a result, later, it would stay on the same line as the last property: value pair:
.rule {
display: block;
clor: #000; }
.rule {
} /* It should look like this when pressing enter after
the opening bracket with the cursor before the closing bracket (obviously). */
I have tried “auto_match_enabled”: false but this simply disables the closing bracket, so I need to add it manually.
I have installed PackageResourceViewer and looked into CSS.sublime-syntax and css_completions.py but could not find any corresponding setting or code. I have also found nothing in the default snippets.
EDIT
How could I get below result?
.rule {
| }
To determine what's happening in response to a key press, open the Sublime console with View > Show Console or the associated key, and enter sublime.log_commands(True) to turn on command logging, then take the action.
In doing this, you can see that in a situation like this:
.rule {|}
When you press Enter, the command that triggers is:
command: run_macro_file {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}
From this you can determine that the key is bound to run_macro_file, and that the macro is what's taking this action. If you look in the default key bindings, the key binding is:
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
},
That is, if you press Enter while auto_indent is turned on, the selection is empty, and the cursor is sitting in the middle of two braces {}, run the macro, which takes the step of inserting multiple lines.
Simplistically, you can thus stop this from happening by turning off auto_indent. However that's not a viable solution generally speaking, so you would need to create a key binding in your User package that, in the same situation doesn't do this and instead just does what enter would do:
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.css" },
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
},
This is the same binding as above, but now the command just inserts a single line, and it also constrains itself only to CSS files via the source.css match in the selector.
With this in place, the css looks like the following when you press the key in this situation:
.rule{
|}
EDIT
The Text in the characters argument of the insert command can be set to any text that you'd like to type, so you could for example set it to "\n\t" or "\n " (newline and two spaces) in order to have a bit of indentation on the new line.
In order to achieve a result like the following, a slightly different command is required:
.rule {
| }
Here there is space before and after the cursor, which precludes the use of the insert command since the cursor always ends up after the last character inserted.
One way to to do this would be to create a macro similar to what already happens for the default binding of this key, but another way would be the insert_snippet command. This can insert a snippet file but it also takes an argument of contents that tells it the snippet content directly.
With that in mind, the above key binding could be expressed as:
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\t"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.css" },
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
]
},
insert_snippet expands out the snippet text (including any fields, if any are provided) and then places the cursor at $0, which defaults to the end of the inserted content if not provided.
Inserting a \t character inserts a tab, which will be a physical tab character unless translate_tabs_to_spaces is turned on, in which case the insertion will replace the \t with the same number of spaces as tab_size is currently set to.
You could of course also use a specific amount of space characters instead, if that is desired.
I've been working on an issue and seem to be stuck, so asking on so in case anyone can help.
To describe the issue, I've got an existing Azure Key Vault setup, and wish to add a number of access policies to this resource group. It needs to be conditional as if the function name is "false" then that function should not be added to key vault access policy.
variable section:
"variables": {
"functionAccess": {
"value": [
{
"name": "[parameters('Function_1')]"
},
{
"name": "[parameters('Function_2')]"
},
{
"name": "[parameters('Function_3')]"
}
]
}
}
My Template :
{
"apiVersion": "2016-10-01",
"condition": "[not(equals(variables('functionAccess')[CopyIndex()].name, 'false'))]",
"copy": {
"batchSize": 1,
"count": "[length(variables('functionAccess'))]",
"mode": "Serial",
"name": "accessPolicies"
},
"name": "[concat(parameters('KeyVault_Name'), '/add')]",
"properties": {
"accessPolicies": [
{
"tenantId": "[subscription().tenantId]",
"objectId": "[if(not(equals(variables('functionAccess')[CopyIndex()].name, 'false')), reference(concat('Microsoft.Web/sites/', variables('functionAccess')[CopyIndex()].name), '2016-08-01', 'Full').identity.principalId, json('null'))]",
"permissions": {
"keys": [
"get",
"list"
],
"secrets": [
"get",
"list"
],
"certificates": [
"get",
"list"
]
}
}
]
},
"type": "Microsoft.KeyVault/vaults/accessPolicies"
}
When I deploy my ARM template for the azure key vault I got this error message:
The language expression property '0' can't be evaluated, property name must be a string.
also tried below, but same error:
{
"apiVersion": "2018-02-14",
"name": "[concat(parameters('KeyVault_Name'), '/add')]",
"properties": {
"copy": [
{
"batchSize": 1,
"count": "[length(variables('functionAccess'))]",
"mode": "serial",
"name": "accessPolicies",
"input": {
"condition": "[not(equals(variables('functionAccess')[copyIndex('accessPolicies')].name, 'false'))]",
"tenantId": "[subscription().tenantId]",
"objectId": "[if(not(equals(variables('functionAccess')[copyIndex('accessPolicies')].name, 'false')), reference(concat('Microsoft.Web/sites/', variables('functionAccess')[copyIndex('accessPolicies')].name), '2016-08-01', 'Full').identity.principalId, json('null'))]",
"permissions": {
"keys": [
"get",
"list"
],
"secrets": [
"get",
"list"
],
"certificates": [
"get",
"list"
]
}
}
}
]
},
"type": "Microsoft.KeyVault/vaults/accessPolicies"
}
There are a few options for dealing with filtering an array for copy operation. I deploy my ARM templates from PowerShell scripts and use PowerShell to setup parameter values. When I need special logic handle different inputs for different environments, I let PowerShell handle it.
If you must handle the filtering in ARM and you have the option to input a CSV list of functions, then perhaps the following will work. You can then use the functionAccessArray to iterate over in the copy operation.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"functionAccessCsv": "Function-0,Function-1,false,Function-4,false,Function-6,Function-7",
"functionAccessFiltered": "[replace(replace(variables('functionAccessCsv'), 'false', ''), ',,', ',')]",
"functionAccessArray": "[split(variables('functionAccessFiltered'), ',')]"
},
"resources": [
],
"outputs": {
"functionAccessCsvFiltered": {
"type": "string",
"value": "[variables('functionAccessFiltered')]"
},
"functionAccessArray": {
"type": "array",
"value": "[variables('functionAccessArray')]"
}
}
}
The result:
I just had the same issue. By using an array parameter with a default value instead of a variable, I got it to work.
"parameters": {
"functionAccess": {
"type": "array",
"defaultValue": [
"value1",
"value2",
"value3"
]
}
}
I'm using Sublime Text 3, and CSS Linter.
In my settings I've put the ignore rule, and currently there is only the "outline-none" rule, I'd like to include all the rules which refer to IE6 and IE7 based errors.
Is there a list what are the IE6 and IE7 rules so that I can put them in the ignore array?
My CSSLint.sublime-settings look like this:
// CSSLint rules you wish to ignore. Must be an array. Leave blank to include all default rules.
{
"ignore": ["outline-none"]
}
To answer my own question, in the end I figured how to do what I need:
{
"user": {
"debug": false,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Danish Royalty/Danish Royalty.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"csslint": {
"#disable": false,
"args": [],
"box-sizing": false,
"errors": "",
"excludes": [],
"ignore": [
"outline-none",
"box-sizing",
"ids",
"adjoining-classes",
"floats",
"qualified-headings",
"unique-headings",
"important",
"universal-selector",
"box-model",
"font-faces",
"font-sizes"
],
"warnings": ""
},
"eslint": {
"#disable": true,
"args": [],
"excludes": []
},
"jscs": {
"#disable": true,
"args": [],
"excludes": []
},
"jshint": {
"#disable": false,
"args": [],
"excludes": [],
"ignore": [
"newcap"
],
"newcap": false,
"tab_size": 4
},
"jslint": {
"#disable": true,
"args": [],
"excludes": [],
"ignore": [
"newcap"
],
"newcap": false
},
"php": {
"#disable": false,
"args": [],
"excludes": []
}
},
"mark_style": "outline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"php": "html",
"python django": "python"
},
"warning_color": "D02000",
"wrap_find": true
}
}
Just go to Preferences > Package Settings > SublimeLinter > Settings - User and paste the above in the opened file.
These are the options that I found not to be of practical importance, so I just ignored them.
Hope it helps :)
I'm trying to figure out how to change Sublime Texts auto bracket rules for css.
I get this by default:
.class {
#CURSOR
}
I would like to have this:
.class {
#CURSOR}
Any ideas on how to accomplish this?
You can add this shortcut to your Key Bindings - User:
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n\t"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "source.css" }
]
}
to modify enter key behaviour with css files.
Or you can use a Snippet. Tools/New Snippet...:
<snippet>
<content><![CDATA[
{
${1}}
]]>
</content>
</snippet>
Save it as Packages/User/CSSBrackets.sublime-snippet.
Then, add a shortcut in your Key Bindings - User to trigger it when pressing { in css files:
{ "keys": ["{"], "command": "insert_snippet", "args": {"name": "Packages/User/CSSBrackets.sublime-snippet"},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.css" }
]
}