Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers

up vote 1 down vote accepted

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"
endfunction

or this:

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

See

: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

:Foo
share|improve this answer
add comment

ed is pretty easy to script with.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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