使用 Vim 编译和运行 C++ 程序

2021-12-24 00:00:00 vim c++

我知道这听起来很愚蠢,但我已经在 Vim 编辑器上编写了 C++ 代码,而且我一生都无法弄清楚如何编译和运行它.我知道这非常简单,但我已经醒了太久了感谢您的帮助!

I know this sounds really dumb, but I've written a C++ code on Vim editor and for the life of me cannot figure out how to compile and run it. I know this is extremely simple but I've been awake for far too long Thanks for the help!

推荐答案

只需输入vim:

:wq

然后,在您的命令行上调用 compiler,它不是 vim 而是 g++clang++或类似的东西:

then, on your command line, invoke the compiler which isn't vim but g++ or clang++ or something like:

g++ -o myCode myCode.cpp

所有在位的选民请阅读该男子本人 Bram Moolenaar 撰写的 vim 用户手册的第 21 节,标题为:走开,然后回来".:help user-manual 会带你到那里.他基本上说在vim中编译或保存并退出,编译然后回来都很酷.根据本节的标题,我认为 Bram 更喜欢后者.他肯定已经精心制作了 vim 以最出色的方式处理后者.当我返回"到任何文件时:光标位于同一行和同一列,我可以像以前一样撤消和重做,我所有的历史记录、搜索、注册以及一切都与我离开时完全一样.和我走的时候基本看不出什么区别!

All you down voters please read section 21 of the vim user's manual by the man himself Bram Moolenaar entitled: "Go away and come back". :help user-manual will get you there. Where he basically says it's cool to either compile in vim OR save and exit, compile, and then come back. By the title of the section I presume Bram prefers the later. He most certainly has crafted vim to handle the later in a most excellent manner. When I "come back" to any file: the cursor is at the same row and column, I can undo and redo as before, and all my history, searches, registers, and everything is exactly as I left it. I basically can't see any difference from when I went away!

重新再次给所有失望的选民 - 窥视者出于许多不同的原因以多种不同的方式使用 vim.我一直在 shell 级别做很多事情,以至于持续留在 vim 中是非常愚蠢的.显然,您的选民在完全不同的情况下工作,在这些情况下,您最好留在编辑器中.请不要以为所有窥视者的工作方式都与您相同.

RE- to all you down voters again - peeps use vim in so many different ways for so many different reasons. I do so much at the shell level all the time that it would be painfully idiotic to remain continuously in vim. You down voters obviously work in completely different situations where you are good to stay inside the editor. Please stop thinking all peeps work the same way as you do.

相关文章