Monday, June 16, 2014

Re: dynamically replace = to " = " when followed by [A-z0-9]

How about something like this:

inoremap <silent> = =<Esc>:call <SID>replaceEqualSign()<CR>a
fun! s:replaceEqualSign()
let pos = virtcol('.')
let n = substitute(getline('.'),'\v([A-z0-9])\=','\1 = ','g')
call setline('.',n)
call cursor(line('.'), pos + 2)
endfun

- Conner


On Mon, Jun 16, 2014 at 04:22:39PM -0400, Ethan Hereth wrote:
>On Mon, Jun 16, 2014 at 3:54 PM, BaRud <bnrj.rudra@live.com> wrote:
>> Hi,
>> I am trying to replace "=" by " = " only when the previous character is [A-z0-9]
>> so, "blah=" should be dynamically replaced by "blah = ", but not !=.
>>
>> In a vim, I can do this by
>>
>> %s/\v([A-z0-9])\=/\1 = /g
>>
>> but, can it be dynamic, or atleast check the current line for every = entered and replace that?
>>
>
>You might be able to use an abbreviation to do this. I have not done
>this but it seems like you can write a function and have the
>abbreviation call the function. See the example under :help
>abbreviation where a function called Eatchar is used to delete a space
>typed after an abbreviation. You might be able to write a function
>that checks to see what character appears before the "=" character and
>insert a space if necessary.
>
>Cheers,
>
>Ethan Alan
>> --
>> --
>> 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.
>
>--
>--
>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.

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