Sublime Text key binding - sublimetext2

I have modified a key binding in sublime text 2, but it is having no effect.
I want to map ctrl+/ to unfold_all command.
I have put this line into my user key bindings file
{ "keys": ["ctrl+/"], "command": "unfold_all" }
But this binding has taken no effect.
Have I entered the syntax incorrectly? Should I modify in the default bindings file?

Special (non-alphanumeric) keys are named, and as it happens the / character is named forward_slash. So, the following should work:
{ "keys": ["ctrl+forward_slash"], "command": "unfold_all" }

Related

How to pull keys and values in jq csv when you don't know the key name

I have a semi working jq filter that pulls out .key, .value.sitename and shows it in a one line csv format. I'd like to add any tag_* keys and values (if found) at the end of the csv line.
[.key , .value.hostname, .value.attributes.sitename ] | #csv
I need help with the .value.attributes.tag* keys since they might be completely missing or different tag_ names. They all start with tag_ but could be anything. I'd like to pair the found tag name and value together if possible and append it on the csv line with the host.
{
"key": "computer1.domain.com",
"value": {
"attributes": {
"TESTID": "23423423",
"sitename": "siteidname",
"tag_robo_equip": "boopbeep",
"tag_modern": "cybertruck"
},
"hostname": "computer1.domain.com",
}
}
At the end of the line "hostname": "computer1.domain.com", the comma is an error.
If you correct this, the solution could be:
Proposal
At the you have 2 additional columns one with the keys an other with the values in your csv file.

JSONPath Syntax when dot in key

Please forgive me if I use the incorrect terminology, I am quite the novice.
I have some simple JSON:
{
"properties": {
"footer.navigationLinks": {
"group": "layout"
, "default": [
{
"text": "Link a"
, "href": "#"
}
]
}
}
}
I am trying to pinpoint "footer.navigationLinks" but I am having trouble with the dot in the key name. I am using http://jsonpath.com/ and when I enter
$.properties['footer.navigationLinks']
I get 'No match'. If I change the key to "footernavigationLinks" it works but I cannot control the key names in the JSON file.
Please can someone help me target that key name?
Having a json response:
{
"0": {
"SKU": "somevalue",
"Merchant.Id": 234
}
}
I can target a key with a . (dot) in the name.
jsonPath.getJsonObject("0.\"Merchant.Id\"")
Note: the quotes and the fact that they are escaped.
Note not sure of other versions, but I'm using
'com.jayway.restassured', name: 'json-path', version: '2.9.0'
A few samples/solutions I've seen, was using singe quotes with brackets, but did not work for me.
For information, jsonpath.com has been patched since the question was asked, and it now works for the example given in the question. I tried these paths successfully:
$.properties['footer.navigationLinks']
$.properties.[footer.navigationLinks]
$.properties.['footer.navigationLinks']
$['properties']['footer.navigationLinks']
$.['properties'].['footer.navigationLinks']
properties.['footer.navigationLinks']
etc.
This issue was reported in 2007 as issue #4 - Member names containing dot fail and fixed.
The fix is not present in this online jsonpath.com implementation, but it is fixed in this old archive and probably in most of the forks that have been created since (like here and here).
Details about the bug
A comparison between the buggy and 2007-corrected version of the code, reveals that the correction was made in the private normalize function.
In the 2007-corrected version it reads:
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){
return "[#"+(subx.push($1||$2)-1)+"]";
}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){
return subx[$1];
});
},
The first and last replace in that sequence make sure the second replace does not interpret a point in a property name as a property separator.
I had a look at the more up-to-date forks that have been made since then, and the code has evolved enormously since.
Conclusion:
jsonpath.com is based on an outdated version of JSONPath and is not reliable for previewing what current libraries would provide you with.
You can encapsulate the 'key with dots' with single quotes as below
response.jsonpath().get("properties.'footer.navigationLinks'")
Or even escape the single quotes as shown:
response.jsonpath().get("properties.\'footer.navigationLinks\'")
Both work fine

sublime text 2 word wrap setting doesn't work

I put this preference.sublime-settings,
{
"ignored_packages":
[
"Vintage"
]
"word_wrap": true
}
But the error comes out like this when I save it: Error trying to parse settings: Unexpected character, expected a comma or closing bracket in ~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings:7:2
what's wrong with this?
You might be facing this problem because the previous property didn't end with a comma. Make sure that there is a comma before you enter any new property. Like there is after font_size in the following illustration.
"font_size": 11,
"ignored_packages":
[
"Vintage"
],
"word_wrap": true
I should have edited Preference.sublime-settings-Default instead of User. That was the problem.

Naming a sublime completion?

I'm wondering if it's possible to "name" a sublime completion so that the name shows up in the auto complete box. With snippets, you can do this by adding a description, but I tried adding that (and name) to the completion with no luck.
To show what I'm trying to accomplish:
The first option is from a snippet with <description>console.log snippet</description> set.
The second option is a completion:
{ "trigger" : "cl" , "description" : "console.log", "contents" : "console.log( ${10} );" }
Use \t after the trigger text. However, there is a bug where buffer completions get blocked when using this feature.
{
"scope": "source.php",
"completions": [
{
"trigger": "trigger_text\tdescription_text",
"contents":"contents_text"
}
]
}

Sublime Text - how to figure out internal command name for key binding?

I'd like to bind a shortcut key to Edit > Tag > Wrap Selection with Tag. How do I figure out the command name so I can put that into the user key bindings?
Hit Ctrl` (backtick) to open the console, then enter
sublime.log_commands(True)
to turn on command logging. Go through the menus and click your target, and
command: insert_snippet {"name": "Packages/XML/long-tag.sublime-snippet"}
comes up. Enter the following into your Preferences -> Key Bindings - User file:
{ "keys": ["ctrl+alt+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } }
(changing the key combo if you wish) and you should be all set. Once you're done, go back to the console and enter
sublime.log_commands(False)
to turn off logging of every single action.
Goto Preferences > Key Bindings - Default then search for alt+shift+w and you'll find the following, on line 566 for me:
{ "keys": ["alt+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } },
You can change the ["alt+shift+w"] to whatever you'd like. I'd suggest making this a new entry in Preferences > Key Bindings - User so you don't overwrite the defaults file.
Go to Preferences -> Settings User
and add the following line:
{ "keys": ["ctrl+shift+w"], "command": "insert_snippet", "args": { "name": "Packages/XML/long-tag.sublime-snippet" } }
(change ctrl+shift+w - to your preferred shortcut)
In general, whenever you want to change a default, go to Preferences -> Settings default and look for the current shortcut - copy the line to the "User" settings and modify it.