Tuesday, September 29, 2020

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



On Tuesday, September 29, 2020 at 4:24:56 PM UTC-4, Tim Chase wrote:
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

Thanks!

Using ctrl-s instead, this does exactly what I asked:

nnoremap <C-S> /<bslash><lt>_\=<c-r><c-w><bslash>><cr>

However, I may not have asked the right question.

I use various plugins to extend searching, such as:
  vim-scripts/Add-to-Word-Search and inkarkat/vim-SearchHighlighting

Ideally I'd like these to automagically inherit the modified search.
I'm just being greedy.

Thanks again!

--
--
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/868e98b2-9b4a-4f00-8cc5-ab9dedfad0f0o%40googlegroups.com.

No comments: