Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 3: Line 3:
 
|previous=1641
 
|previous=1641
 
|next=1643
 
|next=1643
|created=2009
+
|created=December 22, 2009
 
|complexity=basic
 
|complexity=basic
 
|author=Whiteinge
 
|author=Whiteinge
Line 20: Line 20:
 
</pre>
 
</pre>
   
The backslash tells your shell to disregard any aliases for <code>ls</code>; we need plain output with no color. Vim will open, displaying a list of file names.
+
The backslash tells your shell to disregard any aliases for <tt>ls</tt>; we need plain output with no color. Vim will open, displaying a list of file names.
   
 
===Change to list of shell commands===
 
===Change to list of shell commands===
Line 30: Line 30:
 
</pre>
 
</pre>
   
To append <code>.orig</code> to each file name:
+
To append <tt>.orig</tt> to each file name:
 
<pre>
 
<pre>
 
:%s/.*/mv -i '&' '&.orig'/g
 
:%s/.*/mv -i '&' '&.orig'/g
 
</pre>
 
</pre>
   
To change all <code>.JPEG</code> extensions to <code>.jpg</code>:
+
To change all <tt>.JPEG</tt> extensions to <tt>.jpg</tt>:
 
<pre>
 
<pre>
 
:%s/.*/mv -i '&' '&'/g
 
:%s/.*/mv -i '&' '&'/g
Line 52: Line 52:
 
</pre>
 
</pre>
   
<code>\=</code> is substitute command expression. See [[VimTip755]] for more details.
+
<tt>\=</tt> is substitute command expression. See [[VimTip755]] for more details.
   
 
Note: In case the file name contains space character, it should be surrounded with quotes.
 
Note: In case the file name contains space character, it should be surrounded with quotes.
Line 63: Line 63:
 
</pre>
 
</pre>
   
The reason this works is Vim writes a file line-by-line. So if you started with a list of 100 file names, it will execute 100 <code>mv</code> commands. Sure there are utilities that may do this better, but Vim is always available and that's one less thing you have to remember.
+
The reason this works is Vim writes a file line-by-line. So if you started with a list of 100 file names, it will execute 100 <tt>mv</tt> commands. Sure there are utilities that may do this better, but Vim is always available and that's one less thing you have to remember.
   
 
An alternative method of executing the commands is:
 
An alternative method of executing the commands is:
Line 70: Line 70:
 
</pre>
 
</pre>
   
This will pipe the whole buffer to the system command <code>bash</code>, thus executing all of the move commands. This will also replace the file with the command's output, which is useful for commands besides <code>mv</code>. You can also visually select a small subset of lines, and only execute those commands:
+
This will pipe the whole buffer to the system command <tt>bash</tt>, thus executing all of the move commands. This will also replace the file with the command's output, which is useful for commands besides <tt>mv</tt>. You can also visually select a small subset of lines, and only execute those commands:
 
<pre>
 
<pre>
 
:'<,'>!bash
 
:'<,'>!bash
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)