Tuesday, March 23, 2010

Re: how to add line numbers into a document?

Hi Siddhartha!

On Di, 23 Mär 2010, Siddhartha Kasivajhula wrote:

> Hi VI gurus,
> I have a text document with ~500 lines. I want to add a numbering ~to~ this
> document at the beginning of every line. So for example if it's:
>
> This is sentence 1
> This is sentence 2
> And this is sentence 3
>
> I want it to become:
>
> 1. This is sentence 1
> 2. This is sentence 2
> 3. And this is sentence 3
>
> Is there a way to do this in VI? To be clear, I want to actually add the
> numbering to the document, as opposed just have line numbering of the
> document in a sidebar.

If you mean vim, you can do so:

:%s/^/\=printf("%d. ", line('.'))

If you really need vi, you would probably filter your lines through some
awk script like this:

:%! awk '{print NR " " $0}'

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: