I am implementing a custom text object in visual mode, but this text object uses regular expressions to find the beginning and ending of the selection. However, when I do this, other parts of the text are also hilighted. As an additional problem, the searches are added to my search history.
How can these two things be avoided?
EDIT
I'm trying to creating a visual-mode text object, determining the start and end position using the search backward (?
) and search forward (/
) operators, similar to the following (the regular expression is just a test for now).
vnoremap ue ?[^a-zA-Z0-9]\\|^<cr>v/[a-zA-Z0-9]\+/e<cr>
When ue
is pressed in visual mode:
- The above searches backwards for a character that is not
a-z
,A-Z
or0-9
or until the beginning of the line. This is the text?[^a-zA-Z0-9]\\|^<cr>
. - It then enters visual mode with
v
. - It then searches forward for the last character that is
a-z
,A-Z
or0-9
. This is text/[a-zA-Z0-9]\+/e<cr>
.
The above works fine, but ends up highlighting all characters in the last search expression (step 3). I've tried appending :noh<cr>
to the mapping, but this causes the selection to be lost. How can I fix this?
:h search()
?search()
might be getting it to take a count if that's a requirement.