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

Re: i_CTRL-O side-effects

Expand Messages
  • Benji Fisher
    ... Here is another way: 60 = - p Enter Insert-Normal mode. 60 Give the count. = Specify the Expression Register. - Literal string. (I could
    Message 1 of 6 , Aug 7, 2003
    • 0 Attachment
      Ross Presser wrote:
      > Slightly related to this: If I am in insert mode and type ^O60a-[ESC], I end
      > up in normal mode rather than returning to insert mode. I think I see why -
      > the a put me back in insert mode, and the ESC took me out of it, and ^O
      > didn't put me back in. Can anyone confirm this? Is this expected behavior?
      > If it is expected, is there a better way to do what I want - i.e. insert 60
      > dashes then continue typing?

      Here is another way:

      <C-O>60"='-'<CR>p

      <C-O> Enter Insert-Normal mode.
      60 Give the count.
      "= Specify the Expression Register.
      '-' Literal string. (I could have used "-" instead, but I thought
      that "="-" would be confusing.)
      <CR> Enter the value for the Expression Register.
      p Put.

      You can also use (starting from Insert mode, as above)

      <C-R>=RepeatString(60)<CR>

      using the following function (which will be in foo.vim the next time I
      update it):

      function! RepeatString(count, ...)
      " Initialize str to a:1, default to "-" .
      let str = (a:0 ? a:1 : "-")
      let len = strlen(str)
      while len < a:count
      let str = str . str
      let len = len + len
      endwhile
      return strpart(str, 0, a:count)
      endfunction

      HTH --Benji Fisher
    Your message has been successfully submitted and would be delivered to recipients shortly.