Reputation: 7636
Environment: MacOS, gcc, Vim7.2
I know I can do it in Emacs. Compile code and run it. I am wondering how can I do it in vi? I don't want to switch from vi to terminal a lot. thanks! :)
Upvotes: 6
Views: 11874
Reputation: 1765
vim does have a inbuilt :make command, but it has to be associated with the compiler. Some examples are:
GNU gcc compiler:
set makeprg=gcc\ -o\ %<\ %
Intel Fortran compiler:
set makeprg=ifort\ %\ -o\ %<
Upvotes: 6
Reputation: 48626
By typing !
you can execute any shell command by the way.
You can type : to write a command and then write :
:!make
Upvotes: 5
Reputation: 21
In order to complile by just calling :make
you need to have a Makefile in that directory.
Upvotes: 0
Reputation: 1444
Vi understands the command make
directly, so you can just type:
:make
Upvotes: 4
Reputation: 159105
I like to map shell commands to a leader+key. For example, (my leader key is ,
(comma), it's \
by default I believe):
:map <leader>m :!make && ./program<CR>
Then, pressing ,m
(comma then m) executes make && ./program
on the shell (the <CR>
is a carriage return) Once the command has terminated, you will get a prompt to press return, and your focus will go back go vim.
Another workflow you may like is suspending vim using <Control>+Z
, running a command on the shell, and then running fg
to switch back to the backgrounded program.
Upvotes: 1