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

Re: inserting line numbers programmatically

Expand Messages
  • Benji Fisher
    ... There are also several scripts that make this sort of thing easier and more flexible. I have not tried them myself, but a search for scripts with the
    Message 1 of 4 , Nov 1, 2003
    • 0 Attachment
      On Sat, Nov 01, 2003 at 07:55:34PM -0330, Neil Zanella wrote:
      >
      > Hello,
      >
      > I have a text file with N lines. I would like to issue a command such that
      > the lines become prefixed with:
      >
      > LINE1
      > LINE2
      > LINE3
      > LINE4
      > LINE5
      > ...
      >
      > Is this possible with vim? I know there are commands starting with q used
      > to record other commands but I am not sure whether it is possible to make
      > reference to a counter initialized to one and increment the counter from
      > within vim so as to produce the above effect.

      :%s/^/\= "LINE" . line(".")

      :help sub-replace-special

      There are also several scripts that make this sort of thing easier and
      more flexible. I have not tried them myself, but a search for scripts
      with the keyword "number"

      http://www.vim.org/scripts/script_search_results.php?keywords=number&script_type=&order_by=rating&direction=descending&search=search

      shows increment.vim and visincr.vim among others.

      HTH --Benji Fisher
    • David Rock
      ... Here is a link to another thread that is related to doing this. It s from earlier posts to this list: http://groups.yahoo.com/group/vim/message/36212 --
      Message 2 of 4 , Nov 2, 2003
      • 0 Attachment
        * Benji Fisher <benji@...> [2003-11-01 22:50]:
        > On Sat, Nov 01, 2003 at 07:55:34PM -0330, Neil Zanella wrote:
        > >
        > > Hello,
        > >
        > > I have a text file with N lines. I would like to issue a command such that
        > > the lines become prefixed with:
        > >
        > > LINE1
        > > LINE2
        > > LINE3
        > > LINE4
        > > LINE5
        > > ...
        > >
        > > Is this possible with vim? I know there are commands starting with q used
        > > to record other commands but I am not sure whether it is possible to make
        > > reference to a counter initialized to one and increment the counter from
        > > within vim so as to produce the above effect.
        >
        > :%s/^/\= "LINE" . line(".")
        >
        > :help sub-replace-special
        >
        > There are also several scripts that make this sort of thing easier and
        > more flexible. I have not tried them myself, but a search for scripts
        > with the keyword "number"
        >
        > http://www.vim.org/scripts/script_search_results.php?keywords=number&script_type=&order_by=rating&direction=descending&search=search
        >
        > shows increment.vim and visincr.vim among others.
        >

        Here is a link to another thread that is related to doing this. It's
        from earlier posts to this list:
        http://groups.yahoo.com/group/vim/message/36212

        --
        David Rock
        david@...
      • Charles E. Campbell
        ... ... One may use ... to see line numbers (they re not actually made part of the file) or you could use for this.
        Message 3 of 4 , Nov 3, 2003
        • 0 Attachment
          On Sat, Nov 01, 2003 at 07:55:34PM -0330, Neil Zanella wrote:
          > I have a text file with N lines. I would like to issue a command such that
          > the lines become prefixed with:
          > LINE1
          > LINE2
          > LINE3
          ...

          One may use

          :he nu

          to see line numbers (they're not actually made part of the file)
          or you could use <visincr.vim> for this.

          http://vim.sourceforge.net/scripts/script.php?script_id=670
          -or- http://www.erols.com/astronaut/vim/index.html#VimFuncs
          as "Visual Incrementing".

          Regards,
          Chip Campbell

          --
          Charles E Campbell, Jr, PhD _ __ __
          Goddard Space Flight Center / /_/\_\_/ /
          cec@... /_/ \/_//_/
          PGP public key: http://www.erols.com/astronaut/pgp.html
        Your message has been successfully submitted and would be delivered to recipients shortly.