Tuesday, September 11, 2012

Re: Create a 1,000,000 byte file with VIM.

On 11/09/12 13:12, Dotan Cohen wrote:
> I am trying to create a 1,000,000 byte file with VIM. The following
> has VIM using 100% of _both_ my CPUs (Intel DuoCore) for almost two
> hours before I killed it:
> ia<esc>1000000.
>
> /i assume that the holdup is not that 1000000 'a' characters are being
> written, but rather that insert mode is being inserted and left
> 1000000 times. Is there a better way, other than just doing the
> operation 1000 times, then copying that another 1000 times?
>
> Thanks.
>

I think that the following will create a file containing one million
spaces (and *no* carriage-return after them). I haven't tested it. It
mixes ex-commands and normal-mode commands. It assumes that the current
file is not modified. It will fail (with an error) if the required
features are not compiled-in. <Space> and <Esc> are one keypress each.
It assumes that ^ is a valid character in a filename, which is true
under Unix/Linux; I don't know about Windows.

:enew
:setlocal virtualedit=all binary noeol
:set undolevels=0 nobackup nowritebackup
1000000|
i<Space><Esc>
:saveas 10^6spc.txt

For a million 'a' instead, add

:s/ /a/g

before the :saveas but that :substitute operation may be costly.


Best regards,
Tony.
--
Loan-department manager: "There isn't any fine print. At these
interest rates, we don't need it."

--
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

No comments: