How to add string pieces to existing strings in Sublime Text 3?
Example: I have a text with strings like (23aa67) or (ret457) and I would like to transform them into \as{(23aa67)} or \as{(ret457)}.
Is it possible?
This solution will work if you have at least build number 4107 - you can tell by selecting Help → About Sublime Text.
Open your key bindings by selecting Preferences → Key Bindings. The pane on the right is your user key bindings file, and may simply look like this:
[
]
Position your cursor between the brackets and paste in the following:
{
"keys": ["ctrl+alt+super+a"],
"command": "chain",
"args":
{
"commands":
[
{
"command": "expand_selection",
"args": {"to": "smart"}
},
{
"command": "insert_snippet",
"args": {"contents": "\\as{${0:$SELECTION}}"},
}
]
},
"context":
[
{
"key": "selector",
"operator": "equal",
"operand": "text.tex",
"match_all": true
}
]
}
Here's how it works: The key combo CtrlAltSuperA (where Super is the Windows key) initiates two commands - expand_selection and insert_snippet.
You place your cursor between the two parentheses of your original text, and expand_selection expands the selection to include all of the text plus the opening and closing parens.
The second command wraps the selection - ${0:$SELECTION} - with \as{ at the beginning and } at the end. The "context" at the end only allows the command to run in TeX/LaTeX files. This can be removed if you'd like access to it everywhere.
If you want to change the key binding from CtrlAltSuperA to something else, just be sure that you're not overriding another keybinding. The FindKeyConflicts plugin is great for figuring that out.
Make sure you save the key bindings file when you're done. This shortcut will even work with multiple selections, so you can put multiple cursors in multiple places throughout your text, hit the key combo once, and they'll all be wrapped.
Using regular expression, you can do:
Ctrl+H
Find: (\(.+?\))
Replace: \\as{$1}
Replace all
Explanation:
( # start group 1
\( # opening parens, have to be escaped as it has special meaning in regex
.+? # 1 or more any character, not greedy
\) # closing parens
) # end group 1
Replacement:
\\ # backslash, have to be escaped
as{ # literally
$1 # content of group 1
} # literally
Screenshot (before):
Screenshot (after):
the code issue is related to the page: https://obstaclecourse.tricentis.com/Obstacles/41036
The code I used so far is:
*** Settings ***
Library Browser
Library String
# title = TABLE SEARCH
*** Variables ***
*** Test Cases ***
Example Test 70310
OPEN BROWSER https://obstaclecourse.tricentis.com/Obstacles/41036
${txt}= GET TEXT //span[contains(text(),'Table contains')]
#&{tostring}= CONVERT TO STRING ${txt}
# don't forget the spacebar
${endresult}= String.STRIP STRING ${txt} characters=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"?() /
LOG TO CONSOLE ${endresult}
FILL TEXT xpath=//input[#id='resulttext'] ${endresult}
#${text}= GET TEXT id=randomTable
#LOG TO CONSOLE ${text}
Get Text xpath=//body *= You solved this automation problem.
# used resources
the problem is it strips it down to: tains "15"? (True/Fals (and I don't know why that is)
At first I thought I missed the spacebar, so I added that one in, but it didn't give the correct end result.
the problem is it strips it down to: tains "15"? (True/Fals (and I don't know why that is)
Your original string is "Table contains "15"? (True/False)"
You are explicitly asking robot to remove the characters in characters from the string. So, it is going to remove the "T", "a", "b", "l", "e", " ", "c", "o", and "n" from the left, and "e", " ", "(", "T", "r", "u", "e", "/", "F", "a", "l", "s", "e", and ")" from the right since those are all of the characters in the characters parameter.
Hey friends I've been using chrome for the development of my websites but know I wanna switch things up a bit. I read this article on how to do it. I did this in the past for chrome and it worked. But when I paste:
[
{ “keys”: [ “ctrl+alt+v” ], “command”: “view_in_browser” },
{ “keys”: [ “ctrl+alt+f” ], “command”: “view_in_browser”, “args”: { “browser”: “firefox” } },
{ “keys”: [ “ctrl+alt+c” ], “command”: “view_in_browser”, “args”: { “browser”: “chrome” } },
{ “keys”: [ “ctrl+alt+i” ], “command”: “view_in_browser”, “args”: { “browser”: “iexplore” } },
{ “keys”: [ “ctrl+alt+s” ], “command”: “view_in_browser”, “args”: { “browser”: “safari” } }
]
in the key bindings user file I get this error?
Error trying to parse file: Expected value in Packages\User\Default
(Windows).sublime-keymap:3:4
Edit: I was told to turn the curly quotes into straight quotes. I did this and while it did fix the issue of saving the file, the error message did not show up. However I am not able to open Firefox with Ctrl + Alt + f?
The reason that this is not working for you is that your JSON is invalid; JSON only allows for straight double quotes, but the JSON you pasted above is using curly quotes:
From https://en.wikipedia.org/wiki/Quotation_mark:
'...' and "…" are known as neutral, vertical, straight, typewriter, dumb, or ASCII quotation marks. The left and right marks are identical. These are found on typical English typewriters and computer keyboards, although they are sometimes automatically converted to the other type by software.
‘…’ and “…” are known as typographic, curly, curved, book, or smart quotation marks. The beginning marks are commas raised to the top of the line and rotated 180 degrees. The ending marks are commas raised to the top of the line. Curved quotation marks are used mainly in manuscript, printing and typesetting.
As a result of this, Sublime's JSON parser (which is lenient in that it allows for extraneous trailing commas and comments that standard JSON disallows) doesn't understand the curly quotes, so it's not finding what it expects at line 3, column 4.
Replacing all of the double quote characters with straight quotes should solve the problem.
Say I am editing this json
{
"a": {"language": "python"},
"b": {},
"c": {"language": "java"},
"d": {"encoding": "utf-16"}
}
My cursor is at b of "b": {}. I want to delete till the end of current {} block. So it'll look like,
{
"a": {"language": "python"},
"
}
Looks little odd. But explains what I want.
How can I do that in Vim?
You can use d]}.
From :help ]}:
*]}*
]} go to [count] next unmatched '}'.
|exclusive| motion.
The help also says that this is one of the motion's use case:
The above four commands can be used to go to the start or end of the current
code block. It is like doing "%" on the '(', ')', '{' or '}' at the other
end of the code block, but you can do this from anywhere in the code block.
for your example, d]] works too. It is easier to press.
However, ]} is better, since it works no matter which column the { or } sits on.
I have defined the following view:
{ "_id":"_design/test",
"language":"javascript",
"views":
{ "test":
{ "map": "function(doc) { for (var k in doc.data) emit(doc.data[k],null);}",
"options": {"collation":"raw"}
}
}
}
When querying the view without any parameters, I get the expected result (sorted as "AB...ab" instead of "aAbB" because I specified a raw collation):
http://localhost:5985/test/_design/test/_view/test
{"total_rows":13,"offset":0,"rows":[
{"id":"-","key":"A","value":null},
{"id":"-","key":"B","value":null},
{"id":"-","key":"C","value":null},
{"id":"-","key":"D","value":null},
{"id":"-","key":"E","value":null},
{"id":"-","key":"F","value":null},
{"id":"-","key":"a","value":null},
{"id":"-","key":"b","value":null},
{"id":"-","key":"c","value":null},
{"id":"-","key":"d","value":null},
{"id":"-","key":"e","value":null},
{"id":"-","key":"f","value":null},
{"id":"-","key":"g","value":null}
]}
I then use startkey and endkey to ask for the range between B and a, and I expect to receive keys BCDEFa, but instead I receive the following error message:
http://localhost:5985/test/_design/test/_view/test?startkey=%22B%22&endkey=%22a%22
{ "error": "query_parse_error",
"reason": "No rows can match your key range, reverse your start_key and
end_key or set descending=true"
}
Why does it say that no rows can match the key range, when rows B,C,D,E,F and a will match ?
EDIT: I have a single document (revision and ID omitted):
{ "_id": "-",
"_rev": "-",
"data": [ "A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f", "g" ]
}
I can confirm that I experience the same behaviour in version 1.1 on Ubuntu 10.04.
To elaborate:
curl http://localhost:5984/test/_design/test/_view/view?startkey=%22B%22\&endkey=%22a%22
returns the error
{"error":"query_parse_error","reason":"No rows can match your key range, reverse your start_key and end_key or set descending=true"}
while
curl http://localhost:5984/test/_design/test/_view/view?startkey=%22B%22\&endkey=%22D%22
gives
{"total_rows":12,"offset":1,"rows":[
{"id":"stuff","key":"B","value":null},
{"id":"stuff","key":"C","value":null},
{"id":"stuff","key":"D","value":null}
]}
So quoting issues don't look to be the problem.
I am using a single document:
{
"_id": "stuff",
"_rev": "2-0507028fcab427a1b28ed6b3d4a6c05e",
"data": [
"A",
"B",
"C",
"D",
"E",
"F",
"a",
"b",
"c",
"d",
"e",
"f"
]
}
I have found this tip on http://guide.couchdb.org/draft/views.html (paragraph Reversed Results).
hoping that could help you.
Reversed ResultsTo retrieve view results in reverse order, use the descending=true query parameter. If you are using a startkey parameter, you will find that CouchDB returns different rows or no rows at all. What’s up with that?
It’s pretty easy to understand when you see how view query options work under the hood. A view is stored in a tree structure for fast lookups. Whenever you query a view, this is how CouchDB operates:
Starts reading at the top, or at the position that startkey specifies, if present.
Returns one row at a time until the end or until it hits endkey, if present.
If you specify descending=true, the reading direction is reversed, not the sort order of the rows in the view. In addition, the same two-step procedure is followed.
Say you have a view result that looks like this:
KeyValue
0"foo"
1"bar"
2"baz"
Here are potential query options: ?startkey=1&descending=true. What will CouchDB do? See #1 above: it jumps to startkey, which is the row with the key 1, and starts reading backward until it hits the end of the view. So the particular result would be:
KeyValue
1"bar"
0"foo"
This is very likely not what you want. To get the rows with the indexes 1 and 2 in reverse order, you need to switch the startkey to endkey: endkey=1&descending=true:
KeyValue
2"baz"
1"bar"
Now that looks a lot better. CouchDB started reading at the bottom of the view and went backward until it hit endkey.
After looking again through wads of documentation and asking around, it seems that this behavior is unintended. I have submitted a JIRA bug for this. I currently have no general-purpose workaround to suggest, though I have been able to work around the problem in my specific situation.