Pages

Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

May 13, 2011

C Scope alternative

This function really helps as a cscope alternative. check for any variable as "f "
function f() {
local i o m
set -f
test "$ffo" || ffo='! -iname tags'
for i in "$@"; do
case "$i" in
c) ffo='-iname *.[chs]' ;;
h) ffo='-iname *.[h]' ;;
x) ffo='-iregex .*\.[chs][xp+]?[xp+]?' ;;
p) ffo='-iname *.php*' ;;
q) ffo='! -iname tags' ;;
-*) o="$o $i" ;;
*) m="$m $i" ;;
esac
done
test "$m" || return
find . $ffo -type f -print0 \
| xargs -0 grep --colour=always --binary-file=without-match -n $o "${m# }" \
| tee ~/.ff~
set +f
}
function v() {
local cmd
test -s ~/.ff~ || return
if [ "$*" ]; then
grep "$*" ~/.ff~ > ~/.ff- || return
cmd="vim +`head -1 ~/.ff- | cut -d: -f2` `head -1 ~/.ff- | cut -d: -f1 | uniq`"
history -s $cmd
$cmd
else
perl -pe 's/\033[^a-z]*[a-z]//g' ~/.ff~ > ~/.ff
vim -q ~/.ff -c :cw5
fi
}
alias vv='cat ~/.ff~'

vim:Function to comment a visually selected text

In your vimrc add following function

"Function for commenting a block of Visually selected text
function Comment(fl, ll)
let i=a:fl
let comment="//"
while i<=a:ll
let cl=getline(i)
let cl2=comment.cl
call setline(i, cl2)
let i=i+1
endwhile
endfunction
"Function for Un-Commenting a block of Visually selected text
function UnComment(fl, ll)
let i=a:fl
let comment="//"
while i<=a:ll
let cl=getline(i)
let cl2=substitute(cl, "//", "", "")
call setline(i, cl2)
let i=i+1
endwhile
endfunction
" map visual mode keycombo 'com' to this function
vmap com :call Comment(fl, ll)
vmap uncom :call UnComment(fl, ll)