Removed hyphen from word_separators, ctrl+d no longer makes sense
Asked Answered
H

1

4

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 \b, 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.

Haigh answered 31/5, 2014 at 20:25 Comment(6)
Can you post an example of what's happening and what's the expected editor behavior ?Lorsung
@Amir Sure, I added a picture to my questionHaigh
why don't you find 'a' by selecting a with the white space. Or by doing Ctrl + f to find this regex pattern a ?Lorsung
@Amir Selecting with whitespace isn't what I want to do, and that regex pattern is worse than what ctrl+d is doing now. That would match any a character anywhereHaigh
word_separators from the manual: "In some contexts, the text might be tokenized based on other criteria (for example, the syntax definition rules)."Zapateado
Did you highlight a before doing the multiple selection? I know highlighting before selecting will search for the selection, not an exact match.Motivation
V
9

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.

Veloz answered 2/6, 2014 at 18:46 Comment(2)
Do you think this is something that should be in sublime by default? (Having ctrl+d listen to the word_separators setting) Maybe I should mention this to the sublime guys as a feature suggestion?Haigh
@StephenSarcsamKamenar - this has (kind of) already been addressed - see this issue in SublimeText/Issues. Although, this might be sufficiently different that a new issue could be created...Veloz

© 2022 - 2024 — McMap. All rights reserved.