The tutorial mentions that the Ex-mode is for batch processing. Since it is a nuisance, rather than a tool, for me, I would like to see some practical examples. Who uses it? Why?
What is the EX-mode for batch processing for?
migrated from stackoverflow.com Aug 13 '09 at 19:46
This question came from our site for professional and enthusiast programmers.
Vim in Ex mode (also known as
Editing files non-interactively is the most common usage and people using it in similar way as
Ex is also an editor (direct predecessor of vi) and in Vim - Ex Mode emulates
Here is simple example of changing
is equivalent to:
For more advanced solution, you may have file with vim commands and use it by a more classic approach to I/O redirection:
You can also use vim plugins to perform some tasks.
For example the following one-liner would convert your source code file into html using one of the standard plugins:
It'll generate html file (with syntax highlighting) from your code (written in any supported language) which is ready for printing or for publishing on your website.
The following script will create a new html file by downloading html of Example site and replacing its body by auto-generated 20x20 table with random numbers in it:
As of the recent 7.3 which as persistent undo support, ex mode and other forms of vim batch processing is superior to other non-vim methods, since it will not clobber the undo history.
Adding: 'persistent undo' if enabled, keeps all changes to a file (up to a limit) in the undo history, across vim editing sessions. If the file is edited by an external program, vim will reset the undo history when detecting by checksum that it has changed. vim -E will allow you to batch-edit a file and the edit will be in the undo history.
Ex-Mode is mostly for performing the same action on a number of files.
Say you have 25 .html files all with:
Instead of opening each one of those, you could use Ex-mode to change it all to