C Programming in Ubuntu using GVIM and GCC

Requirements :

    1. Ubuntu
    2. GVIM
    3. GCC

Gcc will be already installed in almost every unix based OS. So you need not install.

Gvim :

Text editor. Vi is the initial application. But it is purly command line.
Gvim is graphical interface for vi.
To install gvim
open terminal [ Ctrl + Alt + T]

sudo apt-get install vim-gtk

Enter password
Installation will be completed.

Creating New Project:
Creating project workspace setup.
You can create file anywhere and start working.
But organising things is good.
So now we are going to create a directory called projects in root and create sub projects directory inside that and work in that.
1) Open terminal

2) Make directory for rojects

mkdir /projects/

3) Change permissions as we are creating projects folder in root directory

sudo chmod 777 /projects/

4) cd /projects

5) mkdir test_1
6) cd test_1
Writing your first code with Gvim:
Now you are going to create your first c file.
Open terminal [If you are in terminal already, just use it]
Check whether you are in required direcrtory. [ Currently we should be in test_1.]
Check this by typing ‘pwd’ in terminal.

It should show like /projects/test_1

gvim test_1.c

this will open a text file.

Editing with gvim.

Gvim is like text editor + command line

So to go to text edit mode, press ‘i’

now cursor will be in the text file.

Enter your code

Saving the file in GVIM:

to save the file

1) go to command mode in Gvim [press ‘Esc’]
2) Intitally, if the file is editted, It will have a ‘+’ symbol at its heading bar
3) :w
4) now the file will be saved.
5) Now, If saved, the ‘+’ symbol would have been gone. You can check this.
Compiling :
To compile you should be in the same directory as your file is present in terminal.

1) gcc test_1.c
2) this will compile the test1_1.c file and generate execuatble file if there is no errors in your code
3) The exucutable file will be a.out [ assembly.output is shortened like this]
4) If you want to change the output file name, you can do it while compiling itself.
5) gcc test_1.c -o test_1.out

Running:
To run the executable you had created,

1) go the directory where the executable file is present.
2) ./a.out or ./test_1.out or any other file name you have given

Terminating.
If your program is correct and executes properly, it will mostly terminates by itself.
If your program has any problem or
If your program is running in infinite loop or
If you want to abort the program in the middle
Press ‘Ctrl + c’

To create another project directory and file and executable,
I would recoment to create it on /projects/ directory
cd ../
mkdir test_2
cd test_2
gvim test_2.c
type your program
save it
gcc test_2.c -o test_2.out
./test_2.out

To Edit an existing file:
1) Open the file with GVIM
2) Press ‘i’
3) Your cursor will be in text editor mode.

Why GVIM:

There are several text editors available to code.
But I love gvim and why i am recomending this to you coz,

1) This is free and open source
2) Better syntax highlighting
3) Lot of scripts are available to make so many things very easy
4) Very helpful to navigate, search, explore, and code in huge complex projects even
5) Its better to know the best thing than to start with some crap.

Advertisements

1 thought on “C Programming in Ubuntu using GVIM and GCC”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s