views:

89

answers:

4

I have read the other posts, e.g., http://stackoverflow.com/questions/1830886/vim-executing-a-list-of-editor-commands and others. The answer isn't clear to me for my case. I have some editor commands that I generated from an SQL query. It uses :s/foo/bar to change country codes (from FIPS to a non-standard code set). Here's a sample of the file:

:s/CB/CAMBO
:s/CQ/NMARI
:s/KV/KOSOV
:s/PP/PAPUA
...

I have saved that in a file called fipsToNonStd.vim (unsure about the correct extension). I want to run those commands one after another. What's the easiest way to do so?

Thanks a bunch! SO Rocks!

+6  A: 

I think you're looking for the :source command.

There is online documentation that you can see in vim by running :help :source.

MikeSep
i had just discovered this myself! thanks!
LES2
+1  A: 

:source fileName

LES2
+3  A: 

In general you'd want to just put all those commands into a .vim file. For instance you could save them in a file called convert.vim:

:%s/CD/CAMBO/g
:%s/CQ/NMARI/g
" etcetera

At this point you can load whatever file into Vim and type the following in your editor:

:so convert.vim

Alternately, if this is something you need to do in a pretty scripted basis, then why bother even opening vim? Do it all command line. You could do that by doing something like the following. Modify convert.vim again:

:%s/CD/CAMBO/g
:%s/CQ/NMARI/g
" etcetera
:w!
:q

Then you could just do it all on the command line. Suppose your 'input file' that requires conversion is called data.txt. From the command line you could do:

vim -s convert.vim data.txt

This would process/convert your data for you and save and be done.

dsummersl
A: 

You can put those lines into a function to be called later with :call FName

wbogacz