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

execute commands in macros based on key mappings

Expand Messages
  • Lukas Ruf
    Dear all, I am using vim for nearly all the blabla I have to write. For emails, I defined several mapping for key mappings. Since not everyone follows the
    Message 1 of 6 , Oct 1, 2002
    • 0 Attachment
      Dear all,

      I am using vim for nearly all the blabla I have to write. For emails,
      I defined several mapping for key mappings.

      Since not everyone follows the rules for writing emails properly (as
      mentioned for example on Sven's home page), the execution of macros
      fails if anything cannot be found.

      Is there a way such that I can get vim neglect the result of a command
      (like search-backwards) and get the execution of all the macros being
      carried out irrespective of whether one command fails.

      Thanks for any help!
      --
      Lukas Ruf
      http://www.lpr.ch http://www.maremma.ch
      http://www.{{topsy,nodeos}.net,{promethos,netbeast,rawip}.org}
    • Mikolaj Machowski
      ... Look into :help silence And/or use if statements. Here is my function: exe normal! /^$ ma if search( ^ ---*$ , bw ) if getline( . ) =~ --$ exe
      Message 2 of 6 , Oct 1, 2002
      • 0 Attachment
        On Tue, 1 Oct 2002, Lukas Ruf wrote:

        > Since not everyone follows the rules for writing emails properly (as
        > mentioned for example on Sven's home page), the execution of macros
        > fails if anything cannot be found.
        >
        > Is there a way such that I can get vim neglect the result of a command
        > (like search-backwards) and get the execution of all the macros being
        > carried out irrespective of whether one command fails.

        Look into :help silence
        And/or use if statements. Here is my function:

        exe "normal! /^$\<CR>ma"
        if search("^> ---*$", "bw")
        if getline('.') =~ "--$"
        exe "normal! o ^ You have bad sig delimiter. Insert space after '--'.\<cr>"
        endif
        exe "normal! VGd'az\<cr>"
        endif

        search() dies gracefully when string is not detected.

        Mikolaj
      • Antoine J. Mechelynck
        Mikolaj Machowski wrote: [...] ... [...] ... There is no :help silence I guess you meant :help :silent Tony.
        Message 3 of 6 , Oct 1, 2002
        • 0 Attachment
          Mikolaj Machowski <mikmach@...> wrote:
          [...]
          > Look into :help silence
          [...]
          > Mikolaj

          There is no :help silence

          I guess you meant :help :silent

          Tony.
        • Lukas Ruf
          ... Thanks for the hint! I installed it. However, how can I bind this to an imap definition? Thanks, Lukas -- Lukas Ruf http://www.lpr.ch
          Message 4 of 6 , Oct 3, 2002
          • 0 Attachment
            On Tue, 01 Oct 2002, Mikolaj Machowski wrote:

            >
            > exe "normal! /^$\<CR>ma"
            > if search("^> ---*$", "bw")
            > if getline('.') =~ "--$"
            > exe "normal! o ^ You have bad sig delimiter. Insert space after '--'.\<cr>"
            > endif
            > exe "normal! VGd'az\<cr>"
            > endif
            >
            Thanks for the hint! I installed it.

            However, how can I bind this to an imap definition?

            Thanks,

            Lukas
            --
            Lukas Ruf
            http://www.lpr.ch http://www.maremma.ch
            http://www.{{topsy,nodeos}.net,{promethos,netbeast,rawip}.org}
            Wanna know anything about raw ip? Join rawip@... on www.rawip.org
          • Benji Fisher
            ... First, wrap the Command-mode lines in a function: fun! SigSearchAndDestroy() exe normal! /^$ ma if search( ^ ---*$ , bw ) if getline( . ) =~ --$
            Message 5 of 6 , Oct 3, 2002
            • 0 Attachment
              On Thursday, October 3, 2002, at 11:24 AM, Lukas Ruf wrote:
              >
              > On Tue, 01 Oct 2002, Mikolaj Machowski wrote:
              >
              >>
              >> exe "normal! /^$\<CR>ma"
              >> if search("^> ---*$", "bw")
              >> if getline('.') =~ "--$"
              >> exe "normal! o ^ You have bad sig delimiter. Insert space
              >> after '--'.\<cr>"
              >> endif
              >> exe "normal! VGd'az\<cr>"
              >> endif
              >>
              > Thanks for the hint! I installed it.
              >
              > However, how can I bind this to an imap definition?

              First, wrap the Command-mode lines in a function:

              fun! SigSearchAndDestroy()
              exe "normal! /^$\<CR>ma"
              if search("^> ---*$", "bw")
              if getline('.') =~ "--$"
              exe "normal! o ^ You have bad sig delimiter. Insert space
              after '--'.\<cr>"
              endif
              exe "normal! VGd'az\<cr>"
              endif
              endfun

              The function name is up to you, but should start with a capital letter
              and contain only alphanumeric characters IIRC. Then, make an :imap to
              call the function,

              :imap <F4> :call SigSearchAndDestroy()<CR>

              Note the leading : and trailing <CR> in the second argument.

              HTH --Benji Fisher

              P.S. For more examples, see my file of examples, foo.vim
              http://vim.sourceforge.net/scripts/script.php?script_id=72
            • Lukas Ruf
              ... Yes, it helped a lot! Thanks a lot! Lukas -- Lukas Ruf http://www.lpr.ch http://www.maremma.ch
              Message 6 of 6 , Oct 3, 2002
              • 0 Attachment
                On Thu, 03 Oct 2002, Benji Fisher wrote:

                > HTH --Benji Fisher
                >
                Yes, it helped a lot!

                Thanks a lot!

                Lukas
                --
                Lukas Ruf
                http://www.lpr.ch http://www.maremma.ch
                http://www.{{topsy,nodeos}.net,{promethos,netbeast,rawip}.org}
                Wanna know anything about raw ip? Join rawip@... on www.rawip.org
              Your message has been successfully submitted and would be delivered to recipients shortly.