0

1、按 Tab 自动完成补全 PHP 函数名

首先到 php.net 下载一份 php 源代码并解开
$wget -O php5.3.tar.bz2 http://cn.php.net/get/php-5.3.0.tar.bz2/from/this/mirror
$tar jxf php5.3.tar.bz2

搜索到所有 PHP_FUNCTION 或 ZEND_FUNCTION 关键字
$find ./php.5.3 -type f -name "*.h" -o -name "*.c" | xargs grep -E "PHP_FUNCTION|ZEND_FUNCTION" | sed -e "s/.*_FUNCTION(//g;s/)//g" | sort | uniq > functions.txt

这样就得到一人份完整的 php 内置函数列表.

在 .vimrc 中加入
set dictionary+=d:/php/functions.txt    #保存函数列表的那个文件
set complete-=k complete+=k
function! InsertTabWrapper()
let col=col('.')-1
if !col || getline('.')[col-1] !~ '\k'
return "\<TAB>"
else
return "\<C-N>"
endif
endfunction
inoremap <TAB> <C-R>=InsertTabWrapper()<CR>

保存退出!

2、 Vim 中实现括号自动补全

在 .vimrc 中加入

:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>

function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf

写代码的时候不再担心会丢掉右边的括号了,尤其是函数嵌套的时候

期待你一针见血的评论,Come on!

不用想啦,马上 "登录"  发表自已的想法.