[SATLUG] Vim Kung-Fu

Thomas Weeks tweeksjunk2 at theweeks.org
Sun Oct 17 01:25:40 CDT 2010

On Sunday, October 17, 2010 12:01:39 am Christopher Lemire wrote:
> My contacts list in google (used for most google web apps, google
> voice, gmail, etc.) is very messy. I could edit it through google on
> the web, but that is tedious. I exported the contacts list in all 3
> available formats. None are very readable or understandable. I'd like
> to edit with vim (mostly in command mode) one of these files, and then
> import it back into Google. I googled "edit cvs OR vcf with vim" and I
> came up with unrelated search results, mostly CVS as in Control
> Version System. Any thoughts? How can this be done?

What are you wanting to accomplish or clean up?

I think I might understand what you're wanting.. and if os, there are a couple 
of things that you can do with vim foo.. One is macros. Another are vim 
scripts.  Each are similar.. you take a bunch of vim commands and automate 
stuff with them.  
Macros are sweet.
-hit q to tell vim to start creating a macro
-hit another letter that you want to be the macro name.. like x
-you'll see "recording" pop up..
-Now do whatever you want to automate.. including entering command mode.. 
deleting/removing/replacing, saving, etc..
-when done programming your macro, hit q again to stop recording
-now to execute it, just type @x (where x is your macro letter name)
 it will do it..  likewise, 1000 at x will perform it 1000 times. :)

vim scrips are similar to macros.. but are just vim commands that are stored 
in a separate file.  Just put all your verbatim vim commands in a file, just 
as you would type them after opening a file to edit it.. like this:
	ggi##2010-10-18 This file has been updated
	<esc>:/%s/oldemail at example.com/newemail at example.com/g

Then save the script file.. and invoke it like this:
	$ vim -s vimscriptfile.vim filename

This is great for doing things like replacing email addresses in HTML files or 
the like (what I often use it for anyway.. could also use sed, etc).

What's cool is you can really get fancy with using this with other POSIX 
commands like find:
	fine /var/www -iname "*.html" -exec vim -s myvimscript.vim {} \;

Just like that.. it's modified several thousand html files.. Oh.. plus is 
looks uber cool to visually see all that text flying by being edited visually 
at mach5.. (much cooler than sed ;)

Anyway.. I better get some sleep..

Good luck with your google/vim foo..

And do share some examples of what it is you're doing exactly.


More information about the SATLUG mailing list