Friday, February 2, 2018

Re: Partial current word under cursor

> nnoremap <Leader>s :%s/\<\(<C-r><C-w>\)\>//g<Left><Left>
>
> I was thinking that I would set the cursor where I need to insert
> the new word, as in "get#Something" where # represents the cursor
> and then I'd need to replace it like so:
> s/\<\(left-of-cursor)\zs\ze(right-of-cursor)\>/whatever/g

You might try something like this:

nnoremap <leader>s :%s/\<lt><c-r>=substitute(expand('<cword>'),
'\l\zs\ze\u', '\\zs\\ze', '')<cr>\>//g<left><left>

(all one command in case email decides to add line-breaks).

This will make <leader>s take the current Word under the cursor, look
for the break between the first lowercase letter and the following
uppercase letter (the "#" point in your "get#Something" example) and
add in the \zs and \ze at that point, then use that in a :substitute
command like your original.

It is a special-case for that lower-followed-by-uppercase transition,
but it sounds like that's what you're interested in here.

-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.
For more options, visit https://groups.google.com/d/optout.

No comments: