how to save and exit from a VIM compiler

Asked by Pritam Bhattacharjee on 2013-04-15

I have a written a C-program on VIM text editor. I want to run and execute the program over a GNU interface. Please help on this aspect.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Solved by:
Warren Hill
Solved:
2013-04-16
Last query:
2013-04-16
Last reply:
2013-04-15

Install the build-essential package and you will get an ANSI standard C and C++ compiler

Andrew: I didn't get on what you said, please elaborate.

Moreover, after writing the code on VIM text editor, I'm not able save & exit from there, Help on this aspect too.

in command mode type:

:wq

and it will save the file. I suggest you use nano, it is a lot easier to use and is in a default install of Ubuntu.

Andrew: Nano is a default of Ubuntu, but it is a 3D puzzle game, please suggest something else!

How is it?

CTRL+O to save and CTRL+X to exit. Simples.

Andrew: Its not exiting out, rather the same result is displayed all the time. Please help.

Manfred Hampl (m-hampl) said : #8

Andrew's proposal was to use the nano editor (use the command "nano filename" in a terminal window). What you started most probably was kiki-the-nano-bot game - something completely different.

And the normal "save and close" command in the vim editor is:
hit <esc> to go back to command mode
:write ... write the file
:quit ... quit the vim editor
or as a combination
:wq
This works well, when you have provided a file name when starting the editor and if you have write access to that file.

You wrote "rather the same result is displayed all the time" - what is that result, is there an error message shown?

Best Warren Hill (warren-hill) said : #9

Vim is a very powerful text editor but it's not intuitive to use you have to learn it.

There is a tutorial here:
http://www.openvim.com/tutorial.html

There is a another editor called nano which is easier to pick-up

To create or edit a file type

nano file_name

replacing file_name with the name of the file you want to edit.

If you only edit text files occasionally I would definitely recommend nano.

Thanks Warren, that problem of exiting out from the VIM editor got solved. But, how to run the C-program on the terminal window, so that I can view the outputs of it.

Do I need an Assembler? Where do I get it?

g++ filename

for example

Thanks Warren Hill, that solved my question.

Warren Hill (warren-hill) said : #14

Do you need an assembler: Depends if your code contains assembly or not

Where do you get it:

In a terminal type

sudo apt-get install build-essential

This provides compiler, assembler, standard libraries etc

If your program is C compile with

gcc filename

If its C++

g++ filename