|
hello,
I am very new to vim. I need to process an entire directory of .txt files (>2000), by the following vim commands :e namefile.txt :g/./normal gqq (see http://vimdoc.sourceforge.net/vimfaq.html#14.2) :saveas namefile.txt Is it possible to write some kind of script to process once for all. It is very urgent Thanks a lot mario |
|
Hallo mario
> Is it possible to write some kind of script to process once for all. > It is very urgent > Try :help :argdo HTH Mathias |
|
In reply to this post by mario-3
Hi, mario wrote: > > I am very new to vim. > I need to process an entire directory of .txt files (>2000), by the > following vim commands > :e namefile.txt > :g/./normal gqq (see http://vimdoc.sourceforge.net/vimfaq.html#14.2) > :saveas namefile.txt vim *.txt :argdo execute ":g/./normal gqq" | update Putting the :g-command inside the parameter to execute is necessary, because :global executes all following command, including the :update. Regards, J?rgen -- J?rgen Kr?mer Softwareentwicklung HABEL GmbH & Co. KG mailto:[hidden email] Hinteres ?schle 2 Tel: +49 / 74 61 / 93 53 - 15 78604 Rietheim-Weilheim Fax: +49 / 74 61 / 93 53 - 99 |
|
In reply to this post by mario-3
Hi mario,
1. Open vim 2. Set the current working directory :cd <working directory> 3. Create the argument list :args *.txt After executing this command the number of files in this list is displayed in the Title bar like (1 of 2000). 4. Format all the files in the argument list :argdo :g/./normal gqq 5. Write all the files :wa ~VIshnu -----Original Message----- From: mario [mailto:[hidden email]] Sent: Thursday, July 14, 2005 4:40 PM To: [hidden email] Cc: [hidden email] Subject: please, please quick help. hello, I am very new to vim. I need to process an entire directory of .txt files (>2000), by the following vim commands :e namefile.txt :g/./normal gqq (see http://vimdoc.sourceforge.net/vimfaq.html#14.2) :saveas namefile.txt Is it possible to write some kind of script to process once for all. It is very urgent Thanks a lot mario |
|
In reply to this post by mario-3
----- Original Message -----
From: "mario" <[hidden email]> To: <[hidden email]> Cc: <[hidden email]> Sent: Thursday, July 14, 2005 1:09 PM Subject: please, please quick help. > hello, > I am very new to vim. > I need to process an entire directory of .txt files (>2000), by the > following vim commands > :e namefile.txt > :g/./normal gqq (see http://vimdoc.sourceforge.net/vimfaq.html#14.2) > :saveas namefile.txt > > Is it possible to write some kind of script to process once for all. > It is very urgent > Thanks a lot > mario ":saveas" is mainly for saving under a different name. You could do the following: vim *.txt then, in Vim: :set hidden :set textwidth=80 :bufdo normal ggVGgq :wqa As you see, a script is not even needed (though you may write one as an exercise). Explanation: "vim *.txt" starts vim, tells it it will have to operate on all *.txt files in the current directory, and shows the first one of them in the Vim window. ":set hidden" tells Vim not to complain when a modified file ceases being displayed in a window, but to "hide" the buffer instead. Another possibility (possibly more economical in terms of memory) would be to use ":set autowriteall" instead: prior to abandoning a modified buffer, save it to disk. ":set textwidth=80" tells Vim that we're going to reformat lines to a width of 80 characters. Use another value if that's not what you want. ":bufdo normal ggVGgq" tells it to do the following Normal-mode commands on all buffers (*.txt files) in turn: gg go to top of file V set linewise visual mode G go to bottom of file gq reformat the visual selection (i.e., the whole file) Note: If you want to keep existing linebreaks, a slightly different command will be needed, for instance ":bufdo 1,$g/./gqq" (based on what you proposed). ":wqa" tells Vim to write all modified buffers, then quit. HTH, Tony. |
|
In reply to this post by mario-3
Hello mario,
I think you can do the following: 1. run Vim like: vim *.txt or gvim *.txt this will set arglist to all *.txt files in your directory. see ":h arglist" for more information 2. record macro: qw:g/./normal gqq<enter>:w<enter>:next<enter>q Normal command q will write your typings to register (in this case 'w') and the q command again will stop it. see:":h recording" <enter> here means "enter" key NOT the sequence of chars '<,e,n,t,e,r>'. So this macro in the 'w' register do what you whant and go to the next file in the arglist. 3 Run your macro for all files in the list: 9999@w This is again normal command with count 9999, so it will be executed to the end of the list (I suppose you have less then 10000 files). See ":h @" PS: Try it first on the few fiels (2-3) to see if it really does what you want. Don't know if there is a limit to arglist, does anybody knows? Thursday, July 14, 2005, 2:09:52 PM, you wrote: m> hello, m> I am very new to vim. m> I need to process an entire directory of .txt files (>2000), by the m> following vim commands m> :e namefile.txt m> :g/./normal gqq (see m> http://vimdoc.sourceforge.net/vimfaq.html#14.2) m> :saveas namefile.txt m> Is it possible to write some kind of script to process once for all. m> It is very urgent m> Thanks a lot m> mario -- Best regards, Wind mailto:[hidden email] |
|
In reply to this post by mario-3
yes, thaaaaaaaanks a lot for your kind replies. :-)
J?rgen`s suggestion worked very fine for my present task. I will study the other one. Indeed a very nice ml my best regards mario On Thu, 2005-07-14 at 11:09, mario wrote: > hello, > I am very new to vim. > I need to process an entire directory of .txt files (>2000), by the > following vim commands > :e namefile.txt > :g/./normal gqq (see http://vimdoc.sourceforge.net/vimfaq.html#14.2) > :saveas namefile.txt > > Is it possible to write some kind of script to process once for all. > It is very urgent > Thanks a lot > mario > > > > > > |
| Powered by Nabble | Edit this page |
