Executing commands in normal mode inside vim function
I have normal mappings for two commands, one for invoking LaTeX (mapped to the F6 key), and another for BiBTeX (F5). These work as I expect them to. And I have a function to run them in sequence, to make sure all references and citations are properly inserted. This function is this:
function FullDocumentGeneration() execute "normal \<F6>" execute "normal \<F5>" execute "normal \<F6>" execute "normal \<F6>" endfunction
This works well, except for a detail: after running the commands, a message is shown (in the shell) saying to press Enter to return to vim (as is usual when running shell commands), but then the execution flow enters vim anyway---without me pressing Enter. This is particularly annoying because I usually want to check the program output, so I have to press Ctrl-Z to go back to the shell. Is there anyway of avoiding this? I am doing something wrong in the function?
Presumably, the next mapping interferes with the hit-enter prompt. Try inserting
in between the individual lines, maybe with a echo "Press any key" prepended.
When you use execute, as soon as the command finishes, you drop back into whatever mode you were using before. Since you are writing a function to do what you want to do anyways, why not put it all in one line on your call, e.g. :!cmd line 1 && cmd line2 && cmd line3, and then it'll all go to the shell at once. Or, alternately, you could write a shell script to do what you want, and invoke it on the current file by expanding %. For example, I've been writing with rst and pdflatex, so I have been doing the following.
:!rst2html.py % latex-files/%.tex && cd latex-files && pdflatex %.tex
% expands to the current filename. %:p expands to the absolute path to the current open file.