I'm running some text files written in Markdown through Pandoc to get html, but it renders the tags strangely with weird line breaks and white space in tags, so I've been running a few sed commands in VIM.

Should I be looking at Vimscripts or at macros? Or a shellscript (if I want to combine the VIM commands with the shell Pandoc command)?

I'm running gVIM on Windows 7, and I'm running Pandoc through the regular Windows cmd shell, though I usually do it from inside VIM.

  • Why not use sed to run the sed commands? – Ignacio Vazquez-Abrams Apr 4 '11 at 18:48
  • That's what I'm doing, but I have to run a few of them, and I have to do it every time I convert a file. I'd like to be able to automate the conversion+several sed commands all at once, preferably from within VIM. – Joe Apr 4 '11 at 18:58

I think it depends on where most of the file processing and decision making is being done and on the scripting facilities available to you outside of Vim. Since most of the processing you're doing seems to be running a sequence of programs, perhaps in a pipeline, I'd be inclined to put all that into a shell script or a batch file and launch that from Vim. (You wrote that you use sed. Do you have access to a Unix shell as well?) If you don't have access to a Unix shell and you find yourself limited by the batch file command set, then you could put all the commands into a Vim function. Putting the commands into a Vim function gives you a little more flexibility and easier programming than trying to quote everything just right for a Vim command or mapping.

You can put shell commands inside functions pretty easily like this

function Foo()
    !echo "hello"

or this:

function Bar()
    call system('echo "hello"')


:help usr_41.txt

and especially

:help 41.6
:help 41.7

as well as

:help system()

for more on this. For more on commands and mappings, see

:help usr_40.txt

You can write a command to call your function like this:

:command Foo call Foo()

so that you can execute your function with


ed is pretty easy to script with.

printf "%s\n" "%s/$/...end/" "g/delete.this.line/d" w q | ed filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.