Monday, November 17, 2008

Debugging test program

Well now its time for debugging the test program.
GDB is command line debugger but there are lot of recommendations for DDD on internet.

Its quite easy to use DDD.

Launch DDD and open binary test program. If you have lauched DDD from test folder then DDD will pick test.cpp as source for test binary so no need to load source file explicitly.

DDD UI is not actually good . I was able to step thorough the code . I will keep on posting of new findings about DDD.

Sunday, November 16, 2008

My VIM Tips

File Open/Create:
  • :e create/open a new file
  • :w write file to disk
  • :q quit the window
  • :q! quit without saving
Editing:
  • o: Start writing on line below cursor
  • O: Start writing on line above cursor
  • A: Append character at end of line.
  • s: substitute the character on cursor with new one.

Copy/Paste:
  • yy : copy a line
  • p: paste line below cursor
  • P:paste line on cursor
Search highlight:
Turn off search highlight. Its very annoying when you search something and every search gets highlighted. You can easily turn off that search by '_' key.
nnoremap _ :nohl


Auto Completion
  • Ctrl-n : for auto completion for words already entered in file.
Project Plugin:
  • :let g:proj_flags="imstTvcg" (Add this line to vimrc file)
  • zo,zc Folds and unfolds the folder
  • zO,zC apply folding and unfolding recursiverly
  • \C Create Project
  • Space toggle width of project pane
  • \G search in project
  • F12 : toggle project window
  • \r,\R refreshes the project folder no-recursive and recursively respectively.
  • \I Complete file path of file on cursor on status line.
CTags:
Install ctags
Install taglist plugin
Set in vimrc:
let g:ctags_path='/usr/bin/local/ctags'
let g:ctags_statusline=1
let g:generate_tags =1
nnoremap :Tlist

Abbrevations:
Add following to vimrc:

iab intmain intmain(int argc, char *argv[]){return 0;}
iab #i #include
iab #d #define


Buffer navigation:
map :bprevious
map :bnext
map :bfirst
map :blast

Create Hello World

Create folder test in home diretory

Use vim to create test.cpp and makefile



Contents of test.cpp



#test.cpp 
#include
using namespace std;
int main(int argc, char *argv[])
{
cout<<"Hello World!\n" ;
return;
}


Contents of makefile

 CC = g++
 CFLAGS = -Wall
 LDFLAGS=
 
 SOURCES := test.cpp
 OBJS := $(SOURCES:.cpp =.o)
 
 
 test : $(OBJS)
 $(CC) $(CFLAGS) -o test $(OBJS) $(LDFLAGS) $(LIBS)
 
 .cpp.o:
  $(CC) $(CFLAGS) $(INCLUDES) -c $<    
clean:  
rm *.o temp


   Now just run make from command prompt. First binary is ready!!!

I recommend to go through beginner turtrial about makefile.

Which editor to use for development?

Linux is now setup , bye to Windows!!

Next Step: Which editor to use?

Searched on net for some time found some IDE's

1)Eclipse

2)Anjuta

3)Code Blocks

4)KDevelop

I finally ended with VIM. I dont know but I am little crazy for VIM. I tried learning VIM three times before but gave up , it requires lot of patience. This time I will  hard my best . I have taken printout of all tips. 

I am using it since last two weeks now and feeling little bit comfortable.

Its kind of cool :)

Just using abbrevations I can create class templates.

I am using following scripts for VIM

1)taglist

3)Omnicomplete

3)MiniBuffer Explorer

4)Project Explorer

Just do a little bit research and you can create enviornment like Visual Studio. Plus it looks cool with using different colors and nice tricks that you can show off.

Little Background!!

Well, I am from a Windows background and since last 6 years  only used Visual Studio. Its very good IDE with great debugger and till now it was sufficient for my tasks. 

Now I have started to work on some OpenSource projects and its time to shift to Linux. :)

Hmm. first few days were hard ,setting up Linux . After trying with Redhat,Fedora,OpenSuse I finally ended up with Ubuntu , mostly the reason was easy to use package manager, good  hardware support(I was only able to use wifi on OpenSuse and Ubuntu).