Sublime Text adds \b before the "seach string" duriing find - sublimetext3

Whenever I type something in the sublime text "find" bar,it is enclosed by "\b" and the text is not found even when it is there.
Below pic will explain it clearly.

You have enabled the whole word option in the search dialog (see the button with the quote-symbol), that's what enables the word boundary regular expression.

Related

How to delete all lines in a textpad document which have a specific text

I want to use textpad on a .csv file to remove all lines of text that include the following phrase
"Norwegian Cruise Line"
So it does a search and replace on the following and deletes the whole line and repeats through the document:
"V186552004127",18,**"Norwegian Cruise Line"**,655,9751509,"Norwegian Bliss","Superior","Bahamas & Florida",12/04/2020 00:00:00,"Caribbean","Ocean","Scenery","Adventure","History",9,"New York",0,"New York",1,0,,7,0," ",8.00,19/04/2020 00:00:00,"NYK","New York","USA, NY","Disembark",0,0,"",0,0,0,0
Thanks in advance
You can use the following steps:
Open the Find Dialog with F5
Enter your search term and klick Mark All. This will bookmark all lines containing your serached term.
From the Edit menu or the context menu select Delete|Bookmarked Lines
I'm not sure about textpad, but you can use something like visual studio code or sublime which supports multi line cursors. Then, for example, in visual studio code just highlight the phrase you want and hit ctrl+F2 or right click and hit change all occurrences. From there you can hit ctrl+shift+k to delete the lines.
Using regular expressions in Textpad:
Search:
.*"Norwegian Cruise Line".*\r
Replace With:
(empty)
Replace All
This will search zero o more characters before target text followed by zero or more characters and a newline. Will erase all lines containing "Norwegian Cruise Line" (including quotes).

Sublime Text 3: I can't search a string with a dollar followed by underscore ($_GET, $_POST, etc.)

I can search the following without problems:
_GET
$variable
However, sublime fails to search $_ (p.e. $_GET.) I have tried to escape it somehow:
$\_GET
\$_GET
$__GET
I'm on Ubuntu 14.04LTS
Turn off the regular expressions search. It is the button on the far left of the search field (in this picture currently selected):
With regular expressions turned off:
Although I'm not sure if this would fit your exact problem since you tried escaping using \$_, this answer may still help for posterity.
Did you also make sure "whole word" search is turned off? That's the 3rd button from the left (next to the Aa)
With whole word turned on:
Failing with the attempted escaped \$_:
And it succeeding with _GET:
Note that whole word search of $_ would succeed if there was a whole $_ phrase, surrounded by whitespace. For example with whole word search on:
I am a sentence with the keyword $_ which will be matched.
would work, whereas:
I am a sentence with the keyword $_GET, which will never match. $_POST, $_REQUEST, and $_SERVER won't work either.
would break the whole word search.

Substitute for vim replace in Sublime

I'm looking for a replacement for vim's "replace with character" command--specifically, I want to be able to select some text and replace each character with some character that I type (difficulty: No "vintage" mode)
Example:
Starting with
I am some text with an arbitrary number: 12358998281
I want an easy way to select 12358998281 and turn it into 99999999999, to make the result
I am some text with an arbitrary number: 99999999999
(in vim, this would be done by moving the cursor to the beginning of 12358998281, selecting with ve, then pressing r9)
I can do this by selecting the text, bringing up the "find" dialog, making sure "in selection" and "by regex" are enabled, searching for ., then typing my character into the resulting multiselect. This is incredibly laborious, however, and it prevents me from doing this process on a multiselect (for example, if 12358998281 exists in multiple parts of the file, I might want to quickly replace all instances of it with 99999999999, rather than performing the process above, getting the substitution, copying it to the clipboard, and then replacing with that).
Does Sublime have a command that acts like vim's "replace" that I can bind to something, or do I have to write a macro to get what I need? Or, am I approaching this from entirely the wrong direction?
A more generalized way of thinking of this is "how can I break a select into a multiselect on all characters", if that helps.
By using this package https://sublime.wbond.net/packages/RegReplace you can create regex patterns and bind them to shortcuts.
Also if there are multiple occurrences of one word, you can put cursor on whatever part of the word and press CTRL+D multiple times. One CTRL+D press will select the word under the cursor, every other press will select next occurrence of the word.
You could also use https://sublime.wbond.net/packages/Expand%20Selection%20to%20Whitespace to expand the selection to whitespace if your word contain some random characters, and then press CTDL+D to select next occurrences of the word.
Edit: With the package regex shortcuts indeed you have to create regexes before binding them. But the CTRL+D does work without it.
I don't see a problem with using "Expand selection to whitespace" and than doing the CTRL+D as I wrote in the answer.
I've checked the usage of visual as you wrote in the question and this solution seems much faster to do. You don't have to place cursor in the beggining of the word as It can be whereever in the word and no find/replace is needed, since you'll multiselect all occurrences by holding CTRL+D for a sec and You'll be free to edit it.
You can also use https://sublime.wbond.net/packages/Expand%20Selection%20to%20Quotes to select text inside quote and combine it with CTRL+D if standard CTRL+D doesn't work with some text, or if select to whitespace selects too much text.
I ended up solving this with a simple (if inelegant) plugin:
import sublime_plugin
import sublime
class MultiSelectWithinSelectedCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
new_regions = []
for selected_region in selection:
if selected_region.empty():
selection.add(self.view.word(selected_region))
for selected_region in selection:
if selected_region.a > selected_region.b:
region_begin = selected_region.b
else:
region_begin = selected_region.a
for pos in range(selected_region.size()):
subregion_begin = region_begin + pos
subregion_end = subregion_begin + 1
new_regions.append(sublime.Region(subregion_begin, subregion_end))
selection.clear()
selection.add_all(new_regions)
Once I've stuck this in my plugins directory, I would bind a command in the keymap file like usual:
{ "keys": ["alt+f"], "command": "multi_select_within_selected" }
(with alt+f chosen arbitrarily), and lo, multi-select on all selected characters with a keypress (after which, I can press my replacement character).

Delete anything other than pattern

Let's say this is my text:
this is my text this
is my text this is my text
my text is this
I would like to highlight all text except pattern and delete the highlighted text.
p.e. text: this must be the result.
text
texttext
text
I've found the code how to select all text except pattern:
\%(\%(.{-}\)\#!text\zs\)*
however I don't know how to delete all highlighted text.
This doesn't work:
:%s/\%(\%(.{-}\)\#!bell\zs\)*//
Can anyone help me?
Try this:
:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g
Explanation:
\(^\|\(text\)\#<=\) # means start of line, or some point preceded by “text”
.\{-} # as few characters as possible
\($\|text\)\#= # without globbing characters, checking that we reached either end of line or occurrence of “text”.
Another way to do it:
Create a function that count matches of a pattern in a string (see :help match() to help you design that)
Use: :%s/.*/\=repeat('text', matchcount('text', submatch(0)))
Forgive me, because I'm not a vim expert, but wouldn't prepending the search with v find the inverse so that you could do something like this?
:v/pattern/d
I've implemented Benoit's clever regular expression as a custom :DeleteExcept command in my PatternsOnText plugin. It offers other related commands like :SubstituteExcept or :SubstituteInSearch, too.
OP's example would be
:%DeleteExcept /text/
Comparing that with #Benoit's explicit command (:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g), it's a lot simpler.

searching whole word in Vim (dash character)

I know for searching a whole word I should use /\<mypattern\>. But this is not true for dash (+U002d) character and /\<-\> always fails. I also try /\<\%d45\> and it fails too. anyone know the reason?
Edit2: As #bobbogo mentioned dash is not in 'iskeyword' so I add :set isk+=- and /\<-\> works!
Edit1: I think in Vim /\<word\> only is valid for alphanumeric characters and we shouldn't use it for punctuation characters (see Edit2). I should change my question and ask how we can search punctuation character as a whole world for example I want my search found the question mark in "a ? b" and patterns like "??" and "abc?" shouldn't be valid.
\< matches the zero-width boundary between a non-word character and a word character. What is a word character? It's specified by the isk option (:help isk).
Since - is not in your isk option, then - can never start a word, thus \<- will never match.
I don't know what you want, but /\>-\< will match the dash in hello-word.
Could always search for the regex \byourwordhere\b
As OP said. In order to include dash - into search just execute:
:set isk+=-
Thats all.
Example: When you press * over letter c of color-primary it will search for entire variable name not just for color.

Resources