Re: Partial current word under cursor

2018-02-04 Thread porphyry5
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 s
>   :%s/\<\(\)\>//g
> 
> 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 w yiwq:i%s/\<"\>/"/gF

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 wiXru 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.


Re: Partial current word under cursor

2018-02-02 Thread Tim Chase
> nnoremap s :%s/\<\(\)\>//g
> 
> 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 s :%s/\=substitute(expand(''),
'\l\zs\ze\u', '\\zs\\ze', '')\>//g

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

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


Partial current word under cursor

2018-02-02 Thread S

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 s :%s/\<\(\)\>//g
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


---
This email has been checked for viruses by AVG.
http://www.avg.com

--
--
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.