LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to programming with vi? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-programming-with-vi-492088/)

LinuxNewbie999 10-13-2006 09:37 AM

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

jak2586 10-13-2006 09:40 AM

:wq

together is the command to write and quit mate

LinuxNewbie999 10-13-2006 09:47 AM

debug?
 
how do I debug it? what command?

jak2586 10-13-2006 09:54 AM

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

druuna 10-13-2006 10:06 AM

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.

Zmyrgel 10-13-2006 10:35 AM

Use emacs :D ...

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.

kenyangi5 10-25-2009 05:55 PM

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.

chrism01 10-25-2009 06:31 PM

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.


All times are GMT -5. The time now is 08:57 AM.