Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

regex - Removed hyphen from word_separators, ctrl+d no longer makes sense

I removed the - from the word_separators setting, and that works fine.

But ctrl + d on the word a still matches the "a" in a-b, I don't want it to do that anymore.

It's because ctrl + d wraps your search with regex boundaries , and - is still considered a boundary.

Is there anything I can do to now make ctrl + d not consider - a boundary anymore.

EDIT: picture: enter image description here

The "a" in a-b should not be highlighted, as a-b is a single variable name in this language, which is why I removed the - from word_separators

More clarification: If I'm trying to replace all instance of the variable a, I don't want it matching against parts of other variables, like the "a" in a-b.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From what I can tell from some informal experimenting while answering your other question, the "word_separators" setting seems to primarily relevant when double-clicking to select words. For example, I have the following words in a file:

foobar

and my word_separators list is ./\()"'-:,;<>~!@#%^&*|+=[]{}`~?$, so it includes - and / but not _. If I put my cursor in the first foo (without selecting the whole word first) and hit CtrlD, I get

foobar2

and if I continue hitting CtrlD for several more times, I get

foobar3

so only the "individual words" are selected - foo_bar is not, nor is foobar. However, if I set word_separators to .\()"':,;<>~!@#%^&*|+=[]{}`~?$ (removing - and /) I get the same results when hitting CtrlD repeatedly:

foobar4

- and / are still treated as word separators, even though I removed them from the list. If I add _ to the word_separators list, the results are the same, and only one obvious conclusion can be drawn: word_separators is ignored by CtrlD (find_under_expand).


However, the word_separators list IS used when double-clicking to select a word. With the list like this: .\()"'_:,;<>~!@#%^&*|+=[]{}`~?$ (missing - and /, but with _), double-clicking on foo in each word in turn gives the following:

foobar5

foobar6

foobar7

foobar8

Interestingly, double-clicking on the very first foo gives

foobar9

indicating that the "box" highlighting of similar selections is not paying attention to word_separators.


When using Find -> Find... to search, word_separators is ignored. When nothing is selected and foo is entered into the search box (non-regex search), the following matches are highlighted:

foobar10

This is the same regardless of whether -, /, and/or / are in word_separators or not.

If "Whole Word" is set in the options, the results are a bit different, but again they don't change regardless of whether -, /, and/or / are in word_separators:

foobar11


TL;DR

So, the conclusion is that word_separators is only in effect when double-clicking to select a word. Using a Find dialog or CtrlD (find_under_expand command) relies on some internal separator list, which apparently can't be altered (see my answer here).


A little bit more

Some info I forgot to add earlier: word_separators is also used by some plugins for various sorts of things, such as creating/modifying/otherwise working with selections, doing programmable completions, find and replace, and other sorts of stuff.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...