On 06/11/2010 11:35 AM, fuzzylogic25 wrote:
I tried  :g/cat/.w!>>  out.txt

The problem with this is, for each time it finds one occurrence of cat, it
then appends it to out.txt. So for each occurrence, the hard disk head
moves. This causes alot of mechanical movements.

I've not really had an issue with this -- even a couple thousand file open/write/close iterations is pretty efficient with proper file-system buffering...even on most files I touch on my current box (an ancient Gateway 800MHz Celeron laptop with 384 megs of memory a slow hard-drive, running Debian). If I do have speed issues, I usually turn to another tool like grep:

  grep "pattern" <file.txt >out.txt

which scans the file once, a line at a time (logically...I think the internal implementation reads larger chunks for fewer reads), writing matching lines to the output file which is about as efficient as you can get regardless of file-size.

But the proposed "redir" solutions can also do the write in one pass:

  :redir > outfile.txt
  :g/pattern/
  :redir END

one open, a bunch of writes, one close.

Is it possible to save it to a buffer first, then write ALL of that to the
file?

You can also use the proposed solutions of yanking to a register, pasting that content in a new/empty buffer, and then writing that buffer out to a file.

Also, can you tell me how you got to become experienced with vim? There are
just soo many features/commands i dontk now where/how to start learning

Hanging out on this mailing list puts a lot of experience in your inbox. I've been using Vim for almost 10 years and am still learning new stuff (the 'joinspaces' setting was new to me, thanks to a recent thread). I think the biggest asset is recognizing "I'm doing something where there has to be a better way" and then looking for that solution. The help is the best I've ever used which is also its biggest liability: learning to use/navigate the help will help you when you go looking for better ways to do things. Then practice -- integrate what you've learned into your regular editing routine so that you reach for it automatically...thinking about your editor/editing gets in the way of doing your actual work, so the more you can do things without thinking, the more you can focus on the real task at hand.

Finally, this is the best mailing list I'm on...Several others are pretty good (comp.lang.python, Django Users & Django Developers, and the Sed users) when it comes to signal-to-noise, but they don't hold a candle to the Vim Use mailing list (this is where I give a little praise for the moderators who do such an excellent job of keeping spam off the list! Thanks, ya'll! There are also a lot of smart folks here). So if you feel you're doing something and there's got to be a better way, *ask* on the list. Such as with your current query, you may get multiple different solutions which give you different perspectives on how people think about the problem. Try them out, try to understand what they're doing, and a similar pattern may help you in another situation. And as you can see, some of us are pretty prolix in our responses, providing copious details :)

-tim








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

Reply via email to