0

I'm trying to use query-replace with a prefix argument in superword mode. So for example, C-u M-% token RET token_drawer RET should not replace token where it appears in token_width. But query-replace doesn't seem to respect superword-mode.

I have confirmed that superword-mode is enabled and that, for example, M-f (forward-word) respects it.

How can I convince query-replace that that _ in token_width should be considered part of a word?

1 Answer 1

1

superword-mode defines search functions that can be used to search for word boundaries (see find-word-boundary-function-table). The search functions (like qurey-replace) don't use those functions, and can not be made to use them (I guess).

If you would like _ to be considered as part of a word, then you can modify the syntax table directly using (source evil docs here)

(modify-syntax-entry ?_ "w")

the motion commands also use that table can use this method as instead of superword-mode (you might have to modify the table for some more characters).

If you prefer not to modify the syntax table, then simply use a regex search with patterns like

token\(\[^_]\) => new_pattern\1

see here and (e.g.) replace-regex docstring for the explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.