昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期五, 六月 26, 2009

vim 自动完成函数

还是那句话,用VIM很久了,水平还是菜菜。。。
用VIM写中文的东西其实真的很痛苦,不过现在有了VIM内建的输入法,倒是把这个问题解决了,不用中英文一直切换了。
其实这个功能是借助VIM的自动完成做出来的,自动完成,我从来都只会用,不会写。 最多我会设定字典文件,用CTRL+X,CTRL+K来调用。 今天还是研究了一下万能补全。
看了一篇很好的文章,抄了下面这么一段。 这个还是借助字典的,不过扩展性要强得多。 
func! Mycomp(st,base)
 if a:st

  " locate the start of the word
  let line = getline('.')
  let start = col('.') - 1
  " 直到找到非字母字符或行首
  while start > 0 && line[start - 1] =~ '\a'
  let start -= 1
  endwhile
  return start
  
 else
  " find months matching with "a:base"
  let fname = "dict"
  let res = []
  for line in readfile(fname)
  if line=~a:base
  let res=add(res,line)
  endif
  endfor
  return res


 endif
endfunc
se omnifunc=Mycomp


另外,配合上autocomplpop.vim就很舒服, 不然,一直按 <c-x><c-o> 手指也要抽筋的。


--
Feng

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.