While I mostly use Sublime Text (with the Vintageous plugin) I'm trying to adopt Vim-style practices into my workflow. As you might expect, I'd like to learn how to more quickly jump around a document to edit its content.
For example, let's say I want to jump around and edit the ID values in a JSON file or perhaps jump from the first line of the document down to edit the first name of Gale Gomez.
I understand some of the basic commands like 'change inside quotes' (ci") or 'change word' (cw), I'm hoping to get better at page navigation.
Thoughts or suggestions?
{
"id": 5,
"firstName": "Jayne",
"lasttName": "Norris",
"email": "jaynenorris#talae.com"
},
{
"id": 6,
"firstName": "Gale",
"lasttName": "Gomez",
"email": "galegomez#talae.com"
},
{
"id": 7,
"firstName": "Garner",
"lasttName": "Crane",
"email": "garnercrane#talae.com"
},
{
"id": 7,
"firstName": "Gill",
"lasttName": "Carter",
"email": "gillcarter#talae.com"
},
{
"id": 8,
"firstName": "Evans",
"lasttName": "Douglas",
"email": "evansdouglas#talae.com"
}
To jump to the next ID and edit it:
/"id<return>3wcw
(searches for string "id, goes forward 3 words, then edits the next word, which is the ID's value)
To edit another ID:
n3wcw
(repeats the last search with “n”, then same as before)
Go to the first line of the document:
gg
Change first name of Gale Gomez:
/Gale<return>cw
(searches for “Gale”, then edits it)
And don't forget * to search the word under the cursor (for example id in your case), then n for next occurrence, N for previous occurrence.
# is the same as *, only it searches backward. Actually, I never use that.
If you press / and then <UP> and <DOWN>, then <CR>, you can select and repeat one of your previous searches.
And sometimes when a search hits the last line of the window you may wish to type zz to scroll the window so that the current line will be in the middle of it and you will see some lines below.
Also, you can press % while over an opening/closing parenthesis to jump to the corresponding closing/opening parenthesis.
Related
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):
I'm used Solr 6.6.2
I need to search the special characters and highlight it in Solr,
But it does not work,
my data :
[
{
"id" : "test1",
"title" : "test1# title C# ",
"dynamic_s": 5
},
{
"id" : "test2",
"title" : "test2 title C#",
"dynamic_s": 10
},
{
"id" : "test3",
"title" : "test3 title",
"dynamic_s": 0
}
]
When I search "C#",
Then it will just response like this "test1# title C# ",
It just highlights "C" this word...and "#" will not searching and highlight.
How can I make the search and highlight work for special characters?
The StandardTokenizer splits tokens on special characters, meaning that # will split the content into separate tokens - the first token will be C - and that's what's being highlighted. You'll probably get the exact same result if you just search for C.
The tokenization process will make your tokens end up being test2 title C .
Using a field type with a WhitespaceTokenizer that only splits on whitespace will probably be a better choice for this exact use case, but it's impossible to say if that'll be a good match for your regular search behavior (i.e. if you actually want to match 'C' to `C-99' etc., splitting by those characters can be needed). But - you can use a specific field for highlighting, and that fields analysis chain will be used to determine what to highlight. And you can ask for both the original and the more specific field to be highlighted, and then use the best result in your frontend application.
How can I search a documents named "Hola-Mundo_Army.jpg" searching by the Army* word (always using the asterisk key at the end please)? The thing is that if I search the documents using Army* the result is zero. I think that the problem is the underscore before Army word.
But if I search Mundo_Army* the result is one found, correctly.
docs?api-version=2016-09-01&search=Mundo_Army* <--- 1 result OK
docs?api-version=2016-09-01&search=Army* <--- 0 results and it should find 1 result like the previous search. I always need to use the asterisk at the end.
Thank you!
This is the blob information that I have to search and find:
{
"#search.score": 1,
"content": "{\"azure_cdn\":\"http:\\/\\/dev-dr-documents.azureedge.net\\/localhost-hugo-docs-not-indexed\\/Hola-Mundo_Army.jpg\"}\n",
"source": "dr",
"title": "Hola-Mundo_Army.jpg",
"file_name": "Hola-Mundo_Army.jpg",
"file_type": "Image",
"year_created": "2017",
"client": "LALALA",
"brand": "LELELE",
"description": "HUGO_DEV-TUCUMAN",
"categories": "Clothing and Accessories",
"media": "Online media",
"tags": null,
"channel": "Case Study",
"azuresearch_skipcontent": "1",
"id": "1683",
"metadata_storage_content_type": "application/octet-stream",
"metadata_storage_size": 109,
"metadata_storage_last_modified": "2017-04-26T18:30:35Z",
"metadata_storage_content_md5": "o2yZWelvS/EAukoOhCuuKg==",
"metadata_storage_name": "Hola-Mundo_Army.json",
"metadata_content_encoding": "ISO-8859-1",
"metadata_content_type": "text/plain; charset=ISO-8859-1",
"metadata_language": "en"
}
The best way to troubleshoot cases like this is by using the Analyze API. It will help you understand how your documents and query terms are processed by the search engine. In your case, assuming you are not setting the analyzer property on the field you are searching against, the text Hola-Mundo_Army.jpg is broken down by the default analyzer into the following two terms: hola, mundo_army.jpg. These are the terms that are in your index. That's why, when you are searching for the prefix mundo_army*, the term mundo_army.jpg is matched. Prefix army* doesn't match anything in your index.
You can learn more about the the default behavior of the search engine and how to customize it from this article: How full text search works in Azure Search
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've got an index of hundreds of book titles in elasticserch, with documents like:
{"_id": 123, "title": "The Diamond Age", ...}
And I've got a block of freeform text entered by a user. The block of text could contain a number of book titles throughout it, with varying capitalization.
I'd like to find all the book titles in the block of text, so I can link to the specific book pages.
Any idea how I can do this? I've been looking around for exact phrase matches in blocks of text, with no luck.
You need to index the field title as not_analyzed or using keyword analyzer.
This will tell elasticsearch to do no operations on the field whenever you send a query and this will make you be able to do an exact match search.
I would suggest that you keep an analyzed version as well as a not_analyzed version in order to be able to do exact searches as well as analyzed searches. Your mappings would go like this, in this case I assume that the type name is movies in your case.
"mappings":{
"movies":{
"properties":{
"title":{
"type": "string",
"fields":{
"row":{
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
This will give you two fields title which contains an analyzed title and title.row which contains the exact value indexed with absolutely no processing.
title.row would match if you entered an exact