如何在vi中编译C并运行它?
环境:MacOS、gcc、Vim7.2
我知道我可以在 Emacs 中完成。编译代码并运行它。 我想知道如何在 vi 中做到这一点? 我不想经常从 vi 切换到终端。 谢谢! :)
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! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
vim 确实有一个内置的 :make 命令,但它必须与编译器关联。一些例子是:
GNU gcc 编译器:
Intel Fortran 编译器:
vim does have a inbuilt :make command, but it has to be associated with the compiler. Some examples are:
GNU gcc compiler:
Intel Fortran compiler:
通过输入
!
您可以顺便执行任何 shell 命令。您可以键入 : 来编写命令,然后编写:
By typing
!
you can execute any shell command by the way.You can type : to write a command and then write :
Vi 直接理解命令
make
,因此您只需键入:Vi understands the command
make
directly, so you can just type:我喜欢将 shell 命令映射到引导键+键。例如,(我的前导键是
,
(逗号),我相信默认情况下它是\
):然后,按
,m
(逗号然后m) 执行make && shell 上的 ./program
(
是回车符)命令终止后,您将收到按回车键的提示,并且您的焦点将返回维姆。您可能喜欢的另一个工作流程是使用
+Z
暂停 vim,在 shell 上运行命令,然后运行 fg
切换回后台程序。I like to map shell commands to a leader+key. For example, (my leader key is
,
(comma), it's\
by default I believe):Then, pressing
,m
(comma then m) executesmake && ./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 runningfg
to switch back to the backgrounded program.为了通过调用
:make
进行编译,您需要在该目录中有一个 Makefile。In order to complile by just calling
:make
you need to have a Makefile in that directory.