3

First, I install Vim (Text Editor) in Typical type, on this Windows 7 laptop. And this user that I'm using is an administrator on this computer but couldn't open file in “Program Files” location for writing with Vim. So I change my :cd current directory to my $HOME.

Note: I already have installed Visual Studio Express for Windows Desktop. I just want learn how to use this.

  1. Can I compile C++ code using Vim in Typical type alone on Windows?
  2. If it's possible, then what's the process for compiling C++ code?

I have hello.cpp file but I can't compile it. I already use :comp gcc and :make and the output is: 'make' is not recognized as an internal or external command,

But when I use :comp msvc and :make, the output is: 'nmake' is not recognized as an internal or external command,

Now, what should I do? If it's not possible using Vim alone, how can I compile using Vim with the compiler on my VS Express for Desktop?

6
  • 2
    vim cannot compile C/C++ code by itself. You need to have a compiler for that. Commented Sep 6, 2013 at 9:22
  • 1
    msbuild will come with vs, not make Commented Sep 6, 2013 at 9:23
  • 3
    Use :!<CommandHere> to execute a command in vi. I never use this feature though, I always have a separate terminal open where I do make from because it is much easier to read and respond to compiler output that way. Commented Sep 6, 2013 at 9:23
  • 1
    Though I approve of using vim and the command line, why not open Visual Studio and compile from there (under the build menu)? Commented Sep 6, 2013 at 9:24
  • 2
    You need to set up your PATH environment variable properly for nmake to be found - it's located in one of the VS installation folders - or start vim from the "VS command line" shortcut. Commented Sep 6, 2013 at 11:17

2 Answers 2

7

VIM is a great text editing tool,its like an awesome version of notepad.But it's not a compiler,neither has a build in compiler of itself.So In order to compile the program you'll need a separate compiler installed,like You can use MinGW.

See This : How to use MinGW make with Vim on Windows

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

1 Comment

If you would like to help me deeply, please read my previous comment on Pavel K's answer: stackoverflow.com/questions/18654191/…
3

Vim is just an editor tool. To compile a program you need a compiler tool chain. The one that Visual Studio use is Microsoft Visual Studio C++ Compiler, so you could use it. Or install and use gcc.

The make file that you are generating is used by make utility to actually compile the code for you. There is a Windows version of this tool.

However I would suggest you to perform minimum steps to compile a c++ program manually for better understanding of the process:

Create source .cpp file -> Create object file with a compiler-> create executable with a linker

Good step-by step instructions for Visual c++ here

If you prefer to use gcc, these are good links how to install and use it on Windows.

4 Comments

Vim already included $VIMRUNTIME\compiler\gcc.vim script? So you mean, to be able to use it, I need to install gcc?
@Servant no - you usually use make on linux with gcc to get things to compile. Visual studio does it differently. Or, you can also install a make utility and use that. See msdn.microsoft.com/en-us/library/ms235639.aspx for command line instructions
I thought the compiler made object files, and the linker linked them?
@PavelK Now I know how to compile a C++ program on the command line of Developer Command Prompt for VS2012. Now how can I compile on the command line with Vim and what is the purpose of the command :comp msvc? What is the use of a script in the /compiler directory such as $VIMRUNTIME\compiler\msvc.vim script? I thought msvc means “Microsoft Visual C++”. And what is the use of :make?

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.