Tuesday, September 29, 2020

Re: how to extend search-for-word-under-cursor

On 2020-09-29 13:05, Richard Mitchell wrote:
> Can a search-for-word-under-cursor be extended to search
> for both that word and the same word with a specific leading
> character?
>
> For example, when sitting on "foo", I want to find both "foo"
> and "_foo", but not anything else.

I don't do it regularly, but a couple ideas for you to play with.

1) relax your requirements such that "g*" and "g#" will also find
these matches (":help g*"). However, they find any match, even
non-whole-word matches

2) Pull the current word into a manual search:

/\<_\=<c-r><c-w>\>

This does a search requiring that a word start here ("\<"), has an
optional ("\=") leading underscore, then pulls in the Word under
the cursor with control+R followed by control+W, then finally
requires that the word end here ("\>"). This can be wrapped up in
a mapping (as long as you use proper escaping) if you do it
frequently enough to warrent. Something like this untested

:nnoremap <f2> /<bslash><lt>=<c-r><c-w><bslash>><cr>

might do the trick.

-tim




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200929152444.3b191117%40bigbox.attlocal.net.

No comments: