Tuesday, January 26, 2016

My cscope and ctags setup

Along with my .vimrc setup, I typically use cscope and ctags to navigate around a tree of source code.  I typically setup two bash scripts to separate searching from generation of the files.  This way,
I can generate the search files for a large source tree only if I have to.

The first file I make is the update.sh script:

>------------------------------------ Start of Contents ------------------------------------<

#!/bin/bash

#   Remove all existing files that we use to search
rm -rf *.files *.out tags

#   Build all the tags
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ../.

# find all files for cscope to process
find ../. -name "*.c" -o -name "*.cpp" -o -name "*.s" -o -name "*.h" > cscope.files

#   Generate lookup and reverse lookup databases

cscope -b -q -k

>------------------------------------ End of Contents ------------------------------------<

Then I make the search.sh script:

>------------------------------------ Start of Contents ------------------------------------<

#!/bin/bash

#   Tell Cscope to use gvim ( this will allow multiple files to be open )
export EDITOR=gvim

#   Search with the just built databases
cscope -d


>------------------------------------ End of Contents ------------------------------------<

I keep these scripts in their own directory in a source tree, and work from that directory.
The directory tree is set up like this:


These scripts are setup to go up one directory from cscope directory, and then recursively build a list of .c,.cpp,.s and .h files so that they can be used by cscope to build a lookup database file and a reverse lookup database file.  This speeds up the searching on larger code bases (like the one I use at work).  

Hopefully, this will help someone besides myself.  Have fun.

Saturday, January 23, 2016

My vim / gvim config file

I finally took the time to recreate the .vimrc like I use to have a while ago.  I am posting it here so I don't lose it again, maybe you will find some of it useful.

>------------------------------------ Start of Contents ------------------------------------<

" Set to automatically read when a file is changed from the outside
set autoread

" Always show current position
set ruler

" Configure backspace so it acts as it should act
set backspace=eol,start,indent

" Ignore case when searching
set ignorecase

" When searching try to be smart about cases
set smartcase

" highlight search
set hlsearch

" incremental search
set incsearch

" Don't redraw while executing macros
set lazyredraw

" Regex Magic
set magic

" Extra margin to the left
set foldcolumn=4

" Turn on folding
set foldmethod=syntax

" Enable syntax highlighting
syntax enable

" show partial commands
set showcmd

" display line numbers
set number

" Color Scheme
try
 colorscheme desert
catch
endtry

set guifont=Hack\ 10

set background=dark

" utf8 encoding as en_US default
set encoding=utf8

" Unix file as the standard file type
set ffs=unix,dos,mac

" No backup etc
set nobackup
set nowb
set noswapfile

" Use spaces not tabs, and be smart about it.
" 1 tab = 4 spaces
set expandtab
set smarttab
set shiftwidth=4
set tabstop=4

" Use actual tabs for makefiles only!
autocmd Filetype make   setlocal noexpandtab

" Auto, smart indent
set ai
set si


" Set Window Size
set lines=50 columns=132



>------------------------------------ End of Contents ------------------------------------<

And a picture of what it looks like while viewing  C files: