sponsor Vim development Vim logo Vim Book Ad

Walk.vim : apply a vim command to the files of a directory tree and more (python required)

 script karma  Rating 5/2, Downloaded by 2875  Comments, bugs, improvements  Vim wiki

created by
jean-christophe clavier
script type
This plugin intends to provide facilities to manage sets of files. For
example :
. to create files from visited directory trees and files
. to apply Vim commands on opened files
In fact, it autorizes files and dirs manipulation in many ways

As this plugin can manage many parameters, i decided to put these parameters
in an ini file. Doing so allows you to deal with many mass treatments.
In this ini file, you can specify
. a set of root dirs which trees will be visited. For Each root dir, you can
  define other parameters you estimate useful
. Parameters that contain strings to be written in the outfile :
  . at begining and end of the file (can be connect string for command
  . entering and going out the root dirs
  . entering and going out the visited dirs
  . before and after the files found
  These parameters can contain vim commands (between {{...}}) so you can do
  whatever you want with the file names
. You also have parameters that define
  . a wildcard to filter the files
  . a vim command to apply to the files found
    This command may be written in the iniFile but may also be passed as a
    parameter of the Walk command. If one command is written in the ini file
    and another is passed to the Walk command, the inifile one is
    overwritten by the parameter
    If you want a result to be written in the outfile, this result may be
    written in a register (cf help)
  . the name of the outfile
You've got a complete example of ini file (example.ini) that can be used to
see how this plugin reacts. You just have to modify <SourceDir> and
<OutFile> parameter.
Other iniFile examples have been put in the package :
. One is to generate a tag file with the names of the files found (exTagGen)
. Another is to generate a file to prepare a syntax file to color the names
  of the files found (to be used after exTagGen) (exColTagGen)
  This is not very useful for source files but may be interesting to manage
  simple text files with cross references
. The last is to generate a directory tree (good for CDs' TOC) (exTreeGen)

WGoIniDir     : Change the current dir to the inifiles dir. This is to ease
                manipulation of inifiles
WSetIniFile   : Initialise the inifile global variable
WAddIniFile   : Add the filename passed to the inifile global variable
WEditIniFile  : edits the inifile which name in passed. If this file is
                empty, it is initialized with the content of "skeleton.ini"

Walk          : launch the action, taking the inifiles wich names are
                written in the inifile global variable. Walk accepts an optional
                parameter that contains a vim command to be applied on the
                files found. A powerful way of using this is to define
                user-commands (:help user-commands)

There is other ways to launch the walk operation : you can call the walk
function that way :
:call Walk(cmd,inifile)
All the arguments must be provided (with no completion).
:call Walk("",iniFile)
You can write more than one ini files in the "i" register and type
:call Walk("","") or
:call Walk(cmd,"")

Note : if you use the windows way of calling directories (with \), you must
be careful : you have to write
:call Walk(cmd,'D:\my\directory\myIniFile.ini')
:call Walk(cmd,"D:\\my\\directory\\myIniFile.ini")

Note2: This plugin may be difficult to understand at first glance. Don't hesitate to ask me if you need some more explanation...

Advertising :
Have you heard of this other funny script ?

If you find this script  too serious, try this other one :
With this script you'll be able to MixCase like the best HaRÐco®É mI×CaSE mAs+êR and make your coding very new style ;-)
install details
Warning : this plugin uses python

It is made of four files : Walk.vim, Walk.py, FicIni.py and walk.txt.
The .vim file is to be dropped in the plugins directory, the .txt in the doc
directory and the .py in a directory declared in the python path by a little >
let $PYTHONPATH=$PYTHONPATH . "/MyDirectory/Python"
in your .vimrc

you also have an .ini file examples (example.ini, exTagGen.ini,
exColTagGen.ini and exTreeGen) and a skeleton for .ini files (skeleton.ini).
These files are to be dropped in an inifiles directory (you decide).
Skeleton.ini is used by the WEditIniFile command.
To use the examples, you'll have to edit them to change the <SourceDir> and
the <OutFile> parameter

To ease the edition of the ini files, you have to init another variable in
your .vimrc ($WALKINIDIR): >
let $WALKINIDIR = "MyDirectory/iniFiles"

To init the help tags, start Vim and do either
:helptags ~/.vim/doc (for unix)
:helptags ~\vimfiles\doc (for MSWindows)
to rebuild the tags file. Do ":help add-local-help" for more details.

FicIni.py provides a class to parse xml ini files (details in FicIni.py)


rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
walk.zip 0.9 2007-06-07 6.0 jean-christophe clavier Added a tutorial and a way to call python functions
Walk.zip 0.7 2003-11-24 6.0 jean-christophe clavier added vim help file, reduced use of registers, allowed use of multiple out files and other minor features
Walk.zip 0.6 2003-11-21 6.0 jean-christophe clavier Oups, i uploaded the wrong package
VimWalk.zip 0.4 2003-10-22 6.0 jean-christophe clavier automaticaly opens the outfile at the end
VimWalk.zip 0.3 2003-10-22 6.0 jean-christophe clavier Added commands to ease the parameters passing
vimWalk.zip 0.2 2003-10-21 6.0 jean-christophe clavier Correction of a typing error in the description of the plugin : the register used for the directory was not "n" and is now "d"
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github