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

25650RE: making changes without triggering undo

Expand Messages
  • HALIM,SALMAN (HP-NewJersey,ex2)
    Jan 31, 2002
    • 0 Attachment
      thank you; i use a very similar cursor restoring scheme by benji fisher:
      call Mark() and it returns a string which, when executed, restores the
      cursor and screen. the problem is that i frequently hit 'u' to undo a
      change BEFORE i realize that it might not undo quite the change i have in
      mind and hitting ctrl-r doesn't move the cursor back (and it's too late to
      mark the original location).

      i'm thinking of mapping my 'u' to first save the location and then undoing
      so another mapped key will take me back to where i was before i hit undo.

      a bit kludgy, i fear.

      thank you again,

      salman.

      -----Original Message-----
      From: gary@... [mailto:gary@...]
      Sent: Thursday, January 31, 2002 1:09 PM
      To: HALIM,SALMAN (HP-NewJersey,ex2); 'vim@...'
      Subject: Re: making changes without triggering undo


      Can't help with the undo buffer (perhaps adding "undo" as a {history} to the
      histdel builtin function is an enhancement possibilty?)

      As far as moving the cursor... I've made enough functions that need to move
      someplace, do something, and get back, that I threw together a couple of
      functions to make it easy.

      It doesn't just put the cursor back in the same place, it also gets the
      screen
      back the way it was (i.e., same line at the top of the screen).

      You can give the save/restore functions a token, so you can save/restore
      multiple cursor locations easily (like marks).

      I have this as SaveLoc.vim in my ~/.vim/autoload directory, along with:

      autocmd FuncUndefined * exe 'runtime autoload/' . expand('<afile>')
      . '.vim'

      in my .vimrc

      -gary

      " NOTE:
      " The RestoreLoc function is also in this file, for two reasons.
      "
      " First, it's nice to have this related pair together.
      "
      " Second, RestoreLoc should never be used without first using SaveLoc, so
      " that when SaveLoc is auto-loaded, we'll get RestoreLoc with it. If an
      " attempt is made to use RestoreLoc without first using SaveLoc, the
      " RestoreLoc function will not be found, and we'll get a
      function-not-found
      " failure.

      "
      ============================================================================
      =

      " Save the current cursor position (using the given token, if any) so that
      the
      " same view can be restored (i.e., not just the line/column of the cursor,
      but
      " also which line is at the top of the window).
      "
      function! SaveLoc(...)
      if a:0 == 1
      let token = a:1
      else
      let token = 'saved'
      endif

      exe 'let b:'.token.'_line = line(".")'
      exe 'let b:'.token.'_col = virtcol(".")'
      normal H
      exe 'let b:'.token.'_top = line(".")'

      " Since we just moved the cursor (using H), put it back; we cannot use
      ``
      " since the H in the script doesn't go on the "jump stack".
      "
      exe 'exe b:'.token.'_line'
      exe 'exe "normal " . b:'.token.'_col . "|"'
      endfunction

      "
      ============================================================================
      =

      " Restore the last (given token's, if any) view saved with SaveLoc (above);
      " i.e., not just the line/column of the cursor, but also which line is at
      the
      " top of the window.
      "
      function! RestoreLoc(...)
      if a:0 == 1
      let token = a:1
      else
      let token = 'saved'
      endif

      " Put the saved line at the top of the window.
      exe 'exe b:'.token.'_top'
      normal zt

      " Put the cursor at the saved column on the saved line.
      exe 'exe b:'.token.'_line'
      exe 'exe "normal " . b:'.token.'_col . "|"'
      endfunction

      "
      ============================================================================
      =

      / FROM: "HALIM,SALMAN (HP-NewJersey,ex2)" <salman@...>, Jan 31 9:02
      2002
      | ABOUT: making changes without triggering undo
      |
      | hi,
      |
      | is it possible to make a change to a buffer (say within a function) that
      | doesn't affect the undo buffer? basically, i'm using the header.vim
      plugin
      | which places a timestamp at the top of certain filetypes and updates it
      | every time the file is saved. it works well, except that it affects the
      | undo buffer so if i save something and then hit undo, it undoes the
      | timestamp, requiring a second undo to take me back to the original change
      | which prompted me to save the document.
      |
      | it also moves the cursor, which is inconvenient.
      |
      | it would be nice if there was some way to trigger that timestamp update in
      a
      | way that doesn't modify the undo buffer. can anybody think of a way that
      | that might be accomplished? (it sounds like it may be a new feature
      | request: a command modifier called 'noundo' that works just like 'silent'
      | except that it doesn't affect the undo buffer. although this seems like a
      | bit of a potential security risk.)
      |
      | please advise and comment.
      |
      | thank you,
      |
      | salman.
      |
      \ END: "HALIM,SALMAN (HP-NewJersey,ex2)"
    • Show all 6 messages in this topic