1

It all starts from a shell. For example I am using urxvt with zsh. There I open some file with gvim. In this case it is a LaTeX file. Now I need to execute some command (for compiling the document, e.g.pdflatex).

How can I have the original shell, from where gvim was started, execute that command?

It would also be acceptable if gvim had to open a new shell once and after that execute every future call of the designated command (pdflatex) in that shell, while I can still type in it manually.

The problem with running :!pdflatex directly is, that the output is shown, but if it has gotten too long scrolling is not possible and after I press return, it is all gone.

The idea with using a shell means, that the window focus does not have to switch over by default. So in general the output of my command is visible, but unless an error occurs I can just keep on working in gvim. Now if a new shell was spawned everytime I run the command, this kind of workflow would certainly not be possible.

8
  • I guess gedit has this feature of console. Please have a look. Will get back with more details. Commented Aug 23, 2012 at 11:31
  • 1
    Can you explain further the need of using a single shell? Commented Aug 23, 2012 at 12:21
  • @mtk: sorry, but I won't switch to another editor. Commented Aug 23, 2012 at 12:58
  • 1
    @canaa was a thought, I too stick to VIM, none other is as comforatble as it is :) Commented Aug 23, 2012 at 13:55
  • 1
    @canaaerus: if I understood correctly, the final need is to be able to see the results of previous commands you execute to compile the document. Vim has several features that would help in this task, as quickfix - there are some references on vim-faq. This would allow you to see the results of compilation inside of Vim. Previous results are still available through :cp command, and it would also allow you to jump to specific lines referenced from the errors, despite being able to navigate through results using Vim amazing features. Commented Aug 23, 2012 at 16:38

4 Answers 4

2

GVIM does not retain a "handle" to the shell that launched it in a way that allows it to send commands back to it. Because of they synchronous execution, you also cannot launch a shell from GVIM, keep feeding it commands while also continue working in GVIM.

I'm afraid you have to use the functionality of your window manager to launch (and then later re-activate) a shell window, and send the commands as keystrokes to it. On Windows, this can be done (e.g. in VBScript) via WshShell's Run(), AppActivate() and SendKeys() methods; there are probably similar mechanisms for window control on Linux, too.

If you don't mind having that shell inside your GVIM (emulated, with all its drawbacks), though, there are plugins that enable that.

Sign up to request clarification or add additional context in comments.

1 Comment

I was hoping to be able to pass along a handle when starting gvim, perhaps with gvim -c. Well, I'll just try conque and see if the drawbacks are acceptable.
1

You might want to use Conque. It has drawbacks (can be slow, not so frequently updated, etc) but at least it works for what you expect.

Comments

1

The Vim Wiki as this recipe, which I think will solve your problem by completely removing the need for an external shell. Here it is, in case the source goes dark:

let b:tex_flavor = 'pdflatex'
compiler tex
set makeprg=pdflatex\ \-file\-line\-error\ \-interaction=nonstopmode
set errorformat=%f:%l:\ %m

Basically, you use :make to compile and the quickfix window (:copen) to list errors.

Comments

0

You can run shell commands in vim by calling !command.

For your particular use case of running pdflatex, I added the following shortcut in my /etc/vimrc:

:nmap <F5> :w<CR>:make<CR>

:make will call gnu make in the current directory which will eventually call pdflatex. This is very flexible since the same shortcut will do different thing depending on the directory where you are (if you are coding in C, it will typically call gcc). But you have to be fluent with make :).

So hitting F5 saves my document and compiles it, and saved me hours of typing for multiple years now :).

2 Comments

Thank you for your answer. Unfortunately you missed the main point of the question. The command should not be run in a temporary shell and its output printed inside the gvim window, but in an dedicated console window.
then start this dedicated console window with !urxvt "whatever"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.