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

word complete/change script

Expand Messages
  • Andreas Rapp
    Hi, It would be nice to have a function in normal mode where one could put the cursor on one word and change it to a different out of a group with a single
    Message 1 of 7 , Dec 11, 2000
    • 0 Attachment
      Hi,

      It would be nice to have a function in normal mode where one could put
      the
      cursor on one word and change it to a different out of a group with a
      single keystroke
      for example "close" to "open" and vice versa, or "up" to
      "down","left","right" and so on

      Is there such a function or script already existing ?

      Andreas
    • Douglas L Potts
      ... I ve done something like this, changes true- false (and back), on- off, and could be expanded. It s not very elegant for large numbers of boolean type
      Message 2 of 7 , Dec 11, 2000
      • 0 Attachment
        On Mon, Dec 11, 2000 at 10:22:39AM +0100 Andreas Rapp wrote:
        > Hi,
        >
        > It would be nice to have a function in normal mode where one could put
        > the
        > cursor on one word and change it to a different out of a group with a
        > single keystroke
        > for example "close" to "open" and vice versa, or "up" to
        > "down","left","right" and so on
        >
        > Is there such a function or script already existing ?
        I've done something like this, changes true->false (and back), on->off,
        and could be expanded. It's not very elegant for large numbers of
        boolean type switches, but here goes:

        fu! BoolSwitch(turn_on)
        let curword=expand("<cword>")
        let changed=curword
        if a:turn_on == 1
        if curword == "disable"
        let changed="enable"
        elseif curword == "DISABLE"
        let changed="ENABLE"
        elseif curword == "off"
        let changed="on"
        elseif curword == "OFF"
        let changed="ON"
        elseif curword == "false"
        let changed="true"
        elseif curword == "FALSE"
        let changed="TRUE"
        endif
        else " turn off
        if curword == "enable"
        let changed="disable"
        elseif curword == "ENABLE"
        let changed="DISABLE"
        elseif curword == "on"
        let changed="off"
        elseif curword == "ON"
        let changed="OFF"
        elseif curword == "true"
        let changed="false"
        elseif curword == "TRUE"
        let changed="FALSE"
        endif
        endif
        exe "norm! ciw".changed."\<esc>"
        endf
        nmap ,0 :call BoolSwitch(0)<cr>
        nmap ,1 :call BoolSwitch(1)<cr>

        -Doug

        --
        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        Douglas L. Potts Url: http://www.bigfoot.com/~pottsdl
        "We are too busy mopping the floor to turn off the faucet."
        -Jeff <schaller@...>
        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
      • Andreas Rapp
        Hi Douglas, Thanks, that is what I was looking for Just a maybe stupid question: where do you keep this definition, in the .vimrc ? When I put it there vim
        Message 3 of 7 , Dec 12, 2000
        • 0 Attachment
          Hi Douglas,

          Thanks, that is what I was looking for
          Just a maybe stupid question: where do you keep this definition,
          in the .vimrc ? When I put it there vim complaints, that function is not
          an editor command. I'm using vim 5.0.

          Andreas




          Douglas L Potts schrieb:

          > On Mon, Dec 11, 2000 at 10:22:39AM +0100 Andreas Rapp wrote:
          > > Hi,
          > >
          > > It would be nice to have a function in normal mode where one could put
          > > the
          > > cursor on one word and change it to a different out of a group with a
          > > single keystroke
          > > for example "close" to "open" and vice versa, or "up" to
          > > "down","left","right" and so on
          > >
          > > Is there such a function or script already existing ?
          > I've done something like this, changes true->false (and back), on->off,
          > and could be expanded. It's not very elegant for large numbers of
          > boolean type switches, but here goes:
          >
          > fu! BoolSwitch(turn_on)
          > let curword=expand("<cword>")
          > let changed=curword
          > if a:turn_on == 1
          > if curword == "disable"
          > let changed="enable"
          > elseif curword == "DISABLE"
          > let changed="ENABLE"
          > elseif curword == "off"
          > let changed="on"
          > elseif curword == "OFF"
          > let changed="ON"
          > elseif curword == "false"
          > let changed="true"
          > elseif curword == "FALSE"
          > let changed="TRUE"
          > endif
          > else " turn off
          > if curword == "enable"
          > let changed="disable"
          > elseif curword == "ENABLE"
          > let changed="DISABLE"
          > elseif curword == "on"
          > let changed="off"
          > elseif curword == "ON"
          > let changed="OFF"
          > elseif curword == "true"
          > let changed="false"
          > elseif curword == "TRUE"
          > let changed="FALSE"
          > endif
          > endif
          > exe "norm! ciw".changed."\<esc>"
          > endf
          > nmap ,0 :call BoolSwitch(0)<cr>
          > nmap ,1 :call BoolSwitch(1)<cr>
          >
          > -Doug
          >
          > --
          > *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
          > Douglas L. Potts Url: http://www.bigfoot.com/~pottsdl
          > "We are too busy mopping the floor to turn off the faucet."
          > -Jeff <schaller@...>
          > *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        • Janakiraman .S
          ... vim 5.0. Time to upgrade. Latest is vim5.7. Anyway if you want to put it in your vimrc, you will need to insert a ... you can also put all those lines in a
          Message 4 of 7 , Dec 12, 2000
          • 0 Attachment
            * Andreas Rapp (andreas.rapp@...) wrote thusly :

            > Hi Douglas,
            >
            > Thanks, that is what I was looking for
            > Just a maybe stupid question: where do you keep this definition,
            > in the .vimrc ? When I put it there vim complaints, that function is not
            > an editor command. I'm using vim 5.0.

            vim 5.0. Time to upgrade. Latest is vim5.7.
            Anyway if you want to put it in your vimrc, you will need to insert a
            : before all lines.
            :fu! BoolSwitch(turn_on)
            : let curword=expand("<cword>")
            : let changed=curword
            : if a:turn_on == 1
            :...
            :endfunc
            you can also put all those lines in a file foo.vim and add a line
            source foo.vim to your .vimrc. In that case you wont need to add those
            :'s.

            HTH,
            prince.
          • raf
            ... you don t need to insert : in .vimrc. raf
            Message 5 of 7 , Dec 12, 2000
            • 0 Attachment
              Janakiraman .S wrote:

              > * Andreas Rapp (andreas.rapp@...) wrote thusly :
              >
              > > Hi Douglas,
              > >
              > > Thanks, that is what I was looking for
              > > Just a maybe stupid question: where do you keep this definition,
              > > in the .vimrc ? When I put it there vim complaints, that function is not
              > > an editor command. I'm using vim 5.0.
              >
              > vim 5.0. Time to upgrade. Latest is vim5.7.
              > Anyway if you want to put it in your vimrc, you will need to insert a
              > : before all lines.
              > :fu! BoolSwitch(turn_on)
              > : let curword=expand("<cword>")
              > : let changed=curword
              > : if a:turn_on == 1
              > :...
              > :endfunc
              > you can also put all those lines in a file foo.vim and add a line
              > source foo.vim to your .vimrc. In that case you wont need to add those
              > :'s.
              >
              > HTH,
              > prince.

              you don't need to insert ':' in .vimrc.

              raf
            • Andreas Rapp
              Hi, Then I get the same error, maybe vim 5.0 doesn t know about user functions Andreas
              Message 6 of 7 , Dec 12, 2000
              • 0 Attachment
                Hi,

                Then I get the same error, maybe vim 5.0 doesn't know about user functions

                Andreas

                "Janakiraman .S" schrieb:

                > * Andreas Rapp (andreas.rapp@...) wrote thusly :
                >
                > > Hi Douglas,
                > >
                > > Thanks, that is what I was looking for
                > > Just a maybe stupid question: where do you keep this definition,
                > > in the .vimrc ? When I put it there vim complaints, that function is not
                > > an editor command. I'm using vim 5.0.
                >
                > vim 5.0. Time to upgrade. Latest is vim5.7.
                > Anyway if you want to put it in your vimrc, you will need to insert a
                > : before all lines.
                > :fu! BoolSwitch(turn_on)
                > : let curword=expand("<cword>")
                > : let changed=curword
                > : if a:turn_on == 1
                > :...
                > :endfunc
                > you can also put all those lines in a file foo.vim and add a line
                > source foo.vim to your .vimrc. In that case you wont need to add those
                > :'s.
                >
                > HTH,
                > prince.
              • Janakiraman .S
                ... I think functions were added in vim5.2. ... [...] ... Yup, That is true. I have no idea why i thought it was needed. Maybe if you are gonna put in inside a
                Message 7 of 7 , Dec 12, 2000
                • 0 Attachment
                  * Andreas Rapp (andreas.rapp@...) wrote thusly :

                  > Hi,
                  >
                  > Then I get the same error, maybe vim 5.0 doesn't know about user functions

                  I think functions were added in vim5.2.

                  * raf (raf@...) wrote thusly :

                  > Janakiraman .S wrote:
                  [...]
                  > you don't need to insert ':' in .vimrc.

                  Yup, That is true. I have no idea why i thought it was needed. Maybe if
                  you are gonna put in inside a if endif. Sorry.

                  > raf
                Your message has been successfully submitted and would be delivered to recipients shortly.