On Friday, February 2, 2018 at 2:42:21 PM UTC-8, S wrote:
> Hello!
> 
>     
> 
>     It's a standard practice of mine having to replace whole words with
>     something else, very useful when coding.  I have the following
>     mapping in my vimrc:
> 
>        
>       nnoremap <Leader>s
>       :%s/\<\(<C-r><C-w>\)\>//g<Left><Left>
> 
>     which lets me just hit \+s and replace the current word under the
>     cursor.
> 
>     Now I've found myself needing more and more frequently to insert
>     something in between a word.  For example, say I have the word
>     "getSomething" and I want to replace all occurrences with
>     "getThisSomething", that is insert 'This' in between 'get' and
>     'Something'.  I know how to do this by a hand-written regex but I
>     wanted to create a mapping like the one above.
> 
>     
> 
>     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
> 
>     but I haven't been able to find anything that lets me split the word
>     under the cursor.  It's probably not possible to do with such a
>     simple mapping and I might need a function for it but my knowledge
>     of vim-scripting is next to nothing so I thought you guys could help
>     me figure this out.
> 
>     
> 
>     Thank you very much!
> 
>     -- Sycc90
> 
>     
>   
> 
> 
> 
>       
>         
>               Virus-free. www.avg.com

I use

    nmap <F6>w yiwq:i%s/\<<C-V><C-R>"\>/<C-V><C-R>"/g<Esc>F

as an all-purpose tool for the kind of situation you describe. It copies the 
cursor word and builds the substitute command in the command line window. The 
terminating F invokes backward movement to the next character you type, to 
position the cursor exactly in the 'replacement' part of the command that you 
wish to change.

e.g. with the cursor in the word 'pictiire' that you wish to universally change 
to 'picture', then typing <F6>wiXru<Enter> does so.

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

Reply via email to