how to save and exit from a VIM compiler

Asked by Pritam Bhattacharjee

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:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

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

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#2

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

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#3

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

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#4

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.

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#5

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

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#6

How is it?

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

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#7

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

Revision history for this message
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?

Revision history for this message
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.

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#10

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.

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#11

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

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#12

g++ filename

for example

Revision history for this message
Pritam Bhattacharjee (pritam-bhattacharjee) said :
#13

Thanks Warren Hill, that solved my question.

Revision history for this message
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