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?
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>
ue is pressed in visual mode:
- The above searches backwards for a character that is not
0-9or until the beginning of the line. This is the text
- It then enters visual mode with
- It then searches forward for the last character that is
0-9. This is text
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?