LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-13-2006, 09:37 AM   #1
LinuxNewbie999
Member
 
Registered: Oct 2006
Distribution: FreeBSD
Posts: 162

Rep: Reputation: 30
How to programming with vi?


I having a problem while doing programming with vi. After I entered all the source codes, how do I save it and debug ??
It said :w is to save
:q is exit
But when I entered both nothing happen....


Please tell me step by step.Thanks
 
Old 10-13-2006, 09:40 AM   #2
jak2586
Member
 
Registered: Mar 2006
Location: UK, England, Staffordshire
Distribution: Mandriva 2006, Ubuntu 5.10
Posts: 35

Rep: Reputation: 15
:wq

together is the command to write and quit mate
 
Old 10-13-2006, 09:47 AM   #3
LinuxNewbie999
Member
 
Registered: Oct 2006
Distribution: FreeBSD
Posts: 162

Original Poster
Rep: Reputation: 30
debug?

how do I debug it? what command?
 
Old 10-13-2006, 09:54 AM   #4
jak2586
Member
 
Registered: Mar 2006
Location: UK, England, Staffordshire
Distribution: Mandriva 2006, Ubuntu 5.10
Posts: 35

Rep: Reputation: 15
once its save cant you debug with gcc??

Code:
5.3 Debugger gdb 
You would be using gdb extensively along with Vi. Debugging is the most important aspect of programming as the major cost of software projects goes into debugging and testing. 

To debug C++/C programs use 'gdb' tool. See 'man gdb'. You must compile your programs with -g3 option like 

        gcc -g3 foo.c foo_another.c sample.c

To set up easy aliases do - 

  Setup an alias in your ~/.bash_profile
        alias gdb='gdb -directory=/home/src -directory=/usr/myname/src '
  Give -
        gdb foo.cpp
        gdb> dir /hom2/another_src
        This will add to file search path
        gdb> break 'some_class::func<TAB><TAB>
  This will complete the function name saving you typing time... and will output like -
        gdb> break 'some_class::function_foo_some_where(int aa, float bb)'

Pressing TAB key twice is the command line completion, which will save you lots of typing time. This is one of the most important technique of using gdb.
Reference;

http://www.cs.auckland.ac.nz/referen...m-HOWTO-5.html
 
Old 10-13-2006, 10:06 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

Vi (vim, actually) is 'just' an editor. There's no standard feature that debug's program X's code.

You can extend Vim to include such a feature. Create your own code snippet to do just that (or go on-line and search for one). Here's one that compiles gcc code and runs it, while still inside vim:
Code:
" -----------------------------------------------------------------------------
" Compile (gcc) and run written code
map <F4> :call CompileRunGcc()<CR>
func! CompileRunGcc()
  exec "w"
  exec "!gcc % -o %<"
  exec "! ./%<"
endfunc
Add the above to your .vimrc and, using the F4 function key, your code is compiled and run (or errormessages appear and it won't run ).

This will only compile the gcc code when pressing F3:
Code:
" -----------------------------------------------------------------------------
" Compile (gcc) written code
map <F3> : call CompileGcc()<CR>
func! CompileGcc()
  exec "w" 
  exec "!gcc % -o %<"
endfunc
In general people will exit vim (or open a second terminal / use ctrl-z), run the program (after saving it) see what goes wrong, go back to vim, change code etc etc.

Depending on the language you are programming in and how often you program you could start looking for a specialized editor for that specific language. But vim will do nicely most of the time.

Personally I do all my programming in vim.

Hope this clears things up a bit.
 
Old 10-13-2006, 10:35 AM   #6
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Rep: Reputation: 36
Use emacs ...

I just prefer emacs over vi but that's only my opinnion. It's 'easier' to use than vi.

But you should check some online information about vi so you know what it's capable of so you can alter it to your preferences.
 
Old 10-25-2009, 05:55 PM   #7
kenyangi5
LQ Newbie
 
Registered: Oct 2009
Location: Indiana
Distribution: Mac OSX 10.6.3, Windows Vista, and Ubuntu 9.04
Posts: 1

Rep: Reputation: 0
Well actually vi and vim are in different formats so it just depends on what format you like better. And for the commands
press escape twice to get out of input mode then shift and zz at the same time to exit to main and save. To compile use gcc then to run the program use a.out.

Last edited by kenyangi5; 10-25-2009 at 06:48 PM.
 
Old 10-25-2009, 06:31 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
Actually, in vi & vim (vim = vi improved, so vi + extra capabilities) the cmds are

:w - write to disk
:q - quit, no changes saved
:x - exit+save changes

and many many more; google vi or vim cheatsheet.
 
  


Reply

Tags
how, programming, vi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Userland programming and Kernel Programming.. meetsagittarian Programming 1 02-20-2006 12:26 AM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM


All times are GMT -5. The time now is 02:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration