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

32883Re: execute commands in macros based on key mappings

Expand Messages
  • Benji Fisher
    Oct 3, 2002
      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
    • Show all 6 messages in this topic