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

Re: Creating a new undo block

Expand Messages
  • Spiros Bousbouras
    ... No , this doesn t work. --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information,
    Message 1 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 2 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.