vim中自动补全插件snipmate使用
1、下载snipMatezip:
https://github.com/msanders/snipmate.vim/archive/master.zip
2、解压master.zip
unzip master.zip -d ~/.vim (若是没有此目录,就自己建一个) cd ~/.vim mv snipmate.vim-master/* ./
3、定制自己的快捷键,在~/.vim/snippets/python.snippets 文件中有着各种快捷键的定义,自己也可以添加配置,当然除了c语言之外snipmate还支持其他的各种语言如:shell、ruby、python等, 下面是一个python语言snippets文件
cat /root/.vim/snippets/python.snippets snippet #! #!/usr/bin/env python snippet imp import ${1:module} # Module Docstring snippet docs ''' File: ${1:`Filename('$1.py', 'foo.py')`} Author: ${2:`g:snips_author`} Description: ${3} ''' snippet wh while ${1:condition}: ${2:# code...} snippet for for ${1:needle} in ${2:haystack}: ${3:# code...} # New Class snippet cl class ${1:ClassName}(${2:object}): """${3:docstring for $1}""" def __init__(self, ${4:arg}): ${5:super($1, self).__init__()} self.$4 = $4 ${6} # New Function snippet def def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): """${3:docstring for $1}""" ${4:pass} snippet deff def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): ${3} # New Method snippet defs def ${1:mname}(self, ${2:arg}): ${3:pass} # New Property snippet property def ${1:foo}(): doc = "${2:The $1 property.}" def fget(self): ${3:return self._$1} def fset(self, value): ${4:self._$1 = value} # Lambda snippet ld ${1:var} = lambda ${2:vars} : ${3:action} snippet . self. snippet try Try/Except try: ${1:pass} except ${2:Exception}, ${3:e}: ${4:raise $3} snippet try Try/Except/Else try: ${1:pass} except ${2:Exception}, ${3:e}: ${4:raise $3} else: ${5:pass} snippet try Try/Except/Finally try: ${1:pass} except ${2:Exception}, ${3:e}: ${4:raise $3} finally: ${5:pass} snippet try Try/Except/Else/Finally try: ${1:pass} except ${2:Exception}, ${3:e}: ${4:raise $3} else: ${5:pass} finally: ${6:pass} # if __name__ == '__main__': snippet ifmain if __name__ == '__main__': ${1:main()} # __magic__ snippet _ __${1:init}__${2}
4.使用
这个插件只用了一个键,就是TAB键,
比如对一个C/C++文件,输入inc,再按TAB键,就会填充为#include <stdio.h>,同时stdio被选中,以备修改。还有其他的,如main+TAB, wh+TAB,do+TAB,for+TAB,forr+TAB,if+TAB……具体可以看snippets文件夹下的那些文件,比如c.snippets
比如对于一个python文件,
输入ifmain,再按TAB键,就会填充为
if __name__ == '__main__':
main()
输入imp,再按TAB键,就会填充为
import module
输入wh,再按TAB键,就会填充为
while condition:
# code...