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

Re: comparing register contents?

Expand Messages
  • Hari Krishna Dara
    ... command. ... I don t know at what stage you are trying to check for the @: contents, but I had to deal with a couple of such scenarios before, once in my
    Message 1 of 8 , Nov 30, 2005
    View Source
    • 0 Attachment
      On Wed, 30 Nov 2005 at 1:50pm, Konstantin Rozinov wrote:

      > Oops, now it works..but I realized this is not exactly what I am looking for.
      >
      > If the user types :wq, I want to make some checks and if something isn't
      > right, I do NOT want to quit, but simply "break" out of the q command.
      >
      > So I thought something like this might work:
      > " If a :wq is given, we don't want to quit if data hasn't been saved.
      > if (@: == "wq")
      > set modified
      > endif
      >
      > But, the @: register holds the last command, not the current executing
      command.
      >
      > Anyone have any ideas?
      >
      > Thanks,
      > Konstantin

      I don't know at what stage you are trying to check for the @: contents,
      but I had to deal with a couple of such scenarios before, once in my
      perforce plugin, and another in the clipbrd plugin.

      - In my perforce plugin, when the user edits a specification and types
      :w or :wq, I need to save the specification back to perforce and
      prevent if there is an error, prevent the window from closing (so that
      the user can correct and try to save it again).
      - In the clipbrd plugin, when the user modifies the register and uses
      :w or :wq to save, I bring up a confirmation dialog and on choosing
      "Cancel", avoid closing the window.

      In both these cases, I am using the BufWriteCmd autocommand and set
      'modified' flag to "true" to indicate Vim that the window shouldn't be
      closed. However, there is no way to know if user typed :w or :wq at this
      point, but for me it doesn't really matter (as the user most probably
      already modified the buffer, if not why else would he try to save?), but
      ability to know this would certainly be nice. How important is it for
      you to know this?

      --
      HTH,
      Hari

      >
      >
      >
      > At 01:38 PM 11/30/2005, Tim Chase wrote:
      > >>if (the register ": == "wq")
      > >> then do something....
      > >>I've tried using @: and ": in the conditional of the if statement but
      > >>can't get the syntax quite right...Does anyone have any other ideas?
      > >
      > >Strange that you had trouble with @: as the following worked for me:
      > >
      > >function! LastCommand()
      > > if (@: =~ '^help')
      > > return "just asked for help"
      > > else
      > > return "not help"
      > > endif
      > >endfunction
      > >
      > >
      > >The same thing worked if I checked for
      > >
      > > if (@: == "help")
      > >
      > >I tried it with "wq" instead of "help" as well and it worked too...
      > >
      > >-tim
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      >
      >
      >



      __________________________________
      Start your day with Yahoo! - Make it your home page!
      http://www.yahoo.com/r/hs
    Your message has been successfully submitted and would be delivered to recipients shortly.