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

Re: Creating a new undo block

Expand Messages
  • Ben Fritz
    ... I have this in my .vimrc, to create undo blocks on the rare occasions ... I m not sure in what other contexts this could be used.
    Message 1 of 9 , Apr 1, 2009
    • 0 Attachment
      On Apr 1, 12:31 pm, Spiros Bousbouras <spi...@...> wrote:

      > > so you'd do something like
      >
      > >    imap <f1> <c-g>u<esc>:call Add_line()<cr>
      >
      > This works , thank you. Anyone knows if it's possible to achieve
      > the same effect from within a script ?

      I have this in my .vimrc, to create undo blocks on the rare occasions
      I leave Vim sitting in insert mode (usually by accident):

      > autocmd CursorHoldI * call feedkeys("\<C-G>u", "nt")

      :help feedkeys()

      I'm not sure in what other contexts this could be used.
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... Yes, quite easy to miss. I search for it a few hours ago and didn t find it. I guess the reason for that is that it s a rather late addition. In Vim 6 we
      Message 2 of 9 , Apr 1, 2009
      • 0 Attachment
        On 01/04/09 19:31, Spiros Bousbouras wrote:
        >
        > On 1 Apr, 17:15, Tim Chase<v...@...> wrote:
        >> Spiros Bousbouras wrote:
        >>> function! Add_line()
        >>> call append(0 , "This is a new line")
        >>> endfunction
        >>> imap<F1> <ESC>:call Add_line()<CR>
        >>
        >>> The above script gets executed and now I am in Insert mode. I
        >>> type a few characters and then press<F1>. As expected "This is
        >>> a new line" is added at the top of the buffer. Now if I press 'u'
        >>> it removes the new line *and* the characters I had typed right
        >>> before I pressed<F1>. Is there a way to modify the function
        >>> (preferably) or the mapping so that when I press<F1> a new undo
        >>> block is created so that when I press 'u' only the modification
        >>> by Add_line() gets undone and not what came before I pressed
        >>> <F1> ?
        >>
        >> You should be able to insert an undo-break, curtly described at
        >>
        >> :help i_CTRL-G_u
        >
        > Not only curtly described but also it doesn't appear in the "undo"
        > part of the documentation where I was looking for an answer to
        > my problem.

        Yes, quite easy to miss. I search for it a few hours ago and didn't find
        it. I guess the reason for that is that it's a rather late addition. In
        Vim 6 we would have used other means.

        Note that |i_CTRL-O| also breaks undo, so

        imap <F1> <C-O>:call Add_line()<CR>

        would be good enough (and Vim 6 compatible). In some other
        circumstances, under Vim 6 we would have used

        imap <Space> <Space><Left><Right>
        imap <CR> <CR><Up><Down>

        etc.

        >
        >> so you'd do something like
        >>
        >> imap<f1> <c-g>u<esc>:call Add_line()<cr>
        >
        > This works , thank you. Anyone knows if it's possible to achieve
        > the same effect from within a script ?



        Best regards,
        Tony.
        --
        The best way to make a fire with two sticks is to make sure one of them
        is a match.
        -- Will Rogers

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tobia Conforto
        ... Maybe you could try ending insert mode and entering it again? See :stopinsert and :startinsert Or you could send the u from within the function, using
        Message 3 of 9 , Apr 2, 2009
        • 0 Attachment
          Spiros Bousbouras wrote:
          > Anyone knows if it's possible to achieve the same effect from within
          > a script ?

          Maybe you could try ending insert mode and entering it again?
          See :stopinsert and :startinsert
          Or you could send the <c-g>u from within the function, using
          feedkeys() with the t option, as Ben suggested.

          -Tobia

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Spiros Bousbouras
          ... No , this doesn t work. --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information,
          Message 4 of 9 , Apr 2, 2009
          • 0 Attachment
            On 2 Apr, 04:17, Tony Mechelynck <antoine.mechely...@...> wrote:
            > On 01/04/09 19:31, Spiros Bousbouras wrote:
            >
            > > On 1 Apr, 17:15, Tim Chase<v...@...> wrote:
            > >> Spiros Bousbouras wrote:
            > >>> function! Add_line()
            > >>> call append(0 , "This is a new line")
            > >>> endfunction
            > >>> imap<F1> <ESC>:call Add_line()<CR>
            >
            > >>> The above script gets executed and now I am in Insert mode. I
            > >>> type a few characters and then press<F1>. As expected "This is
            > >>> a new line" is added at the top of the buffer. Now if I press 'u'
            > >>> it removes the new line *and* the characters I had typed right
            > >>> before I pressed<F1>. Is there a way to modify the function
            > >>> (preferably) or the mapping so that when I press<F1> a new undo
            > >>> block is created so that when I press 'u' only the modification
            > >>> by Add_line() gets undone and not what came before I pressed
            > >>> <F1> ?
            >
            > >> You should be able to insert an undo-break, curtly described at
            >
            > >> :help i_CTRL-G_u
            >
            > > Not only curtly described but also it doesn't appear in the "undo"
            > > part of the documentation where I was looking for an answer to
            > > my problem.
            >
            > Yes, quite easy to miss. I search for it a few hours ago and didn't find
            > it. I guess the reason for that is that it's a rather late addition. In
            > Vim 6 we would have used other means.
            >
            > Note that |i_CTRL-O| also breaks undo, so
            >
            > imap <F1> <C-O>:call Add_line()<CR>
            >
            > would be good enough (and Vim 6 compatible).

            No , this doesn't work.

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Spiros Bousbouras
            ... I tried function! Add_line() startinsert call feedkeys( u , nt ) stopinsert call append(0 , This is a new line ) endfunction imap :call
            Message 5 of 9 , Apr 2, 2009
            • 0 Attachment
              On 2 Apr, 13:35, Tobia Conforto <tobia.confo...@...> wrote:
              > Spiros Bousbouras wrote:
              > > Anyone knows if it's possible to achieve the same effect from within
              > > a script ?
              >
              > Maybe you could try ending insert mode and entering it again?
              > See :stopinsert and :startinsert
              > Or you could send the <c-g>u from within the function, using
              > feedkeys() with the t option, as Ben suggested.

              I tried

              function! Add_line()
              startinsert
              call feedkeys("\<C-G>u", "nt")
              stopinsert
              call append(0 , "This is a new line")
              endfunction
              imap <F1> <ESC>:call Add_line()<CR>

              but it doesn't bring the desired result.

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            Your message has been successfully submitted and would be delivered to recipients shortly.