Reputation: 4903
I need to write lot of code and compile very often. I hate switching back and forth various windows just to compile the code. Is it possible to open a small window at bottom and run invoke shell and close that window when needed?
Upvotes: 0
Views: 980
Reputation: 207445
Maybe map a key to shell out to the compiler and run the program if compilation is successful:
:map F8 :!cc % && ./a.out
Or maybe just
:sh
make run
Ctrl-D
Another option is to suspend vi
, using Ctrl-Z and do your stuff in the shell, then type fg
to bring vim
back to the foreground. Note that this is actually a feature of your shell, rather than vim
but it produces the effect you seek.
Note this idea originates from the book "Efficient Linux at the Command Line" by Daniel Barrett. I forget the page number.
Upvotes: 0
Reputation: 11576
I use tmux
to achieve something like that. I have the following in my ~/.tmux.conf file:
bind s splitw -v -p 25 -c '#{pane_current_path}' '/bin/bash'
bind q kill-pane
On pressing Ctrl-b + s (prefix + s), a new pane containing a bash shell opens up at the bottom. I can run shell commands from there: find, grep, make, etc. When I'm done, I press Ctrl-b + q to close the shell.
To enable tmux
on every bash session, add the following to your ~/.bashrc:
[[ -z "$TMUX" ]] && exec tmux
Upvotes: 0
Reputation: 196546
With GVim or MacVim, you can run external commands in the command-line: Gvim/MacVim comes with a (very) limited shell that will happily show you whatever the compiler outputs. The general usage pattern is:
:!command
:!command %
With CLI Vim, the same method will pause Vim and return to the shell to execute your command.
In both cases, you'll get a message asking you to press ENTER to come back to your normal editing.
Using :make | cw
would be a slightly more sophisticated alternative, with the added bonus of showing the errors in the quickfix window.
An even more sophisticated approach would be to use Tim Pope's Dispatch plugin in combination with tmux or screen.
Upvotes: 1
Reputation: 109
Sounds like a problem for Screen http://www.gnu.org/software/screen/
Quick reference of commands http://aperiodic.net/screen/quick_reference
Upvotes: 0