Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two stages to this, firstly get all the files you want to edit into the argument list, then add the filename to the lines.</p> <p><b>1) Add files to argument list.</b></p> <p>Either start vim with "gvim *.txt" (if your shell can handle 700 files listed on the command line) or, load gvim with no files open (so the argument list is empty) and then:</p> <pre><code>cd /path/to/files " Get the list of files let filelist = glob('*.txt') " Add files to the argument list for file in split(filelist, '\n') exe 'argadd ' . file endfor </code></pre> <hr> <p><strong>EDIT:</strong></p> <p>A cleaner way of doing this is:</p> <pre><code>:cd /path/to/files :exe 'args' glob('*.txt') </code></pre> <p><strong>END OF EDIT</strong></p> <hr> <p><b>2) Do the required filtering on all files:</b></p> <pre><code>:argdo %s/^/\=expand('%:t') . ' '/ | w </code></pre> <p><b>Explanation:</b></p> <p><b><code>argdo</code></b> runs the command on every file in the argument list.</p> <p><b><code>%s/FROM/TO/</code></b> replaces FROM with TO</p> <p><b><code>^</code></b> is the start of the line (so the replacement adds TO to the start of the line)</p> <p><b><code>\=</code></b> means that TO should be the result of an expression</p> <p><b><code>expand('%:t')</code></b> gives the name of the current file (%), only including the tail (':t'), so no leading directory name.</p> <p><b><code>. ' '</code></b> appends a space.</p> <p><b><code>|</code></b> is the command joining character, so after the substitution, it runs:</p> <p><b><code>w</code></b>, which writes the file to disk.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload