Loading ...
Sorry, an error occurred while loading the content.
 

Using substitute to replace current word

Expand Messages
  • Mark Woodward
    Hi vimmers, I m looking for a more efficient way to do this. I m trying to replace a word with a word ( or string ) from an input statement. The exe statement
    Message 1 of 3 , Jun 2, 2003
      Hi vimmers,
      I'm looking for a more efficient way to do this. I'm trying to replace a
      word with a word ( or string ) from an input statement. The exe statement is
      working but I suspect 'substitute' might be a better way? Any thoughts? I
      know I could use command line :s// , but this is just an exercise in writing
      plugins.

      --
      Mark


      " function to replace the current word
      fu! <SID>RepWord()

      let s:str = expand("<cword>")
      let @z = input("Replace |".s:str."| with what? ")

      exe "normal viws^O@z"

      " something like:
      " :s/s:str/@z/e
      " tried substitute but obviously not doing it right!

      endfunction
    • Mikolaj Machowski
      On Mon, Jun 02, 2003 at 11:14:41PM +1000, Mark Woodward wrote: Why mess with registers? ... let newword = input( Replace | .s:str. | with what? ) exe normal
      Message 2 of 3 , Jun 2, 2003
        On Mon, Jun 02, 2003 at 11:14:41PM +1000, Mark Woodward wrote:

        Why mess with registers?

        > " function to replace the current word
        > fu! <SID>RepWord()
        > let s:str = expand("<cword>")
        let newword = input("Replace |".s:str."| with what? ")
        exe "normal viws".newword."\<esc>" " :normal should end in Normal mode

        if you want with :s/// try:
        exe "normal :s/".s:str."/".newword."/e\<cr>"


        > " tried substitute but obviously not doing it right!
        > endfunction

        m.
      • Mark Woodward
        ... Thanks Mikolaj, I didn t realise you could concatenate an exe command like this but I see now that s exactly what is outlined under :h exe ;-) -- Mark
        Message 3 of 3 , Jun 3, 2003
          > if you want with :s/// try:
          > exe "normal :s/" .s:str. "/" .newword. "/e\<cr>"

          Thanks Mikolaj,
          I didn't realise you could concatenate an exe command like this but I
          see now that's exactly what is outlined under :h exe ;-)

          --
          Mark
        Your message has been successfully submitted and would be delivered to recipients shortly.