2013-03-24 17 views
0

我在vimrc中有一個函數。該功能是關於完成html中的標籤。如何調用vimrc中的函數取決於文件類型

42 function! InsertHtmlTag() 
43  let pat = '\c<\w\+\s*\(\s\+\w\+\s*=\s*[''#$;,()."a-z0-9]\+\)*\s*>' 
44  normal! a> 
45  let save_cursor = getpos('.') 
46  let result = matchstr(getline(save_cursor[1]), pat) 
47  if (search(pat, 'b', save_cursor[1])) 
48   normal! lyiwf> 
49   normal! a</ 
50   normal! p 
51   normal! a> 
52  endif 
53  :call cursor(save_cursor[1], save_cursor[2], save_cursor[3]) 
54 endfunction 
55 inoremap > <ESC>:call InsertHtmlTag()<CR> 

但是最近我發現了一些麻煩。當我編寫C++代碼時,在我編寫#include <iostream>之後,vim用</iostream>完成它。...... 只有當文件類型是.html時,纔會調用此函數。

回答

2

Vim允許特定於文件類型的配置。將摘錄從~/.vimrc移至例如~/.vim/ftplugin/html_inserttag.vim,使映射緩衝區局部:

inoremap <buffer> > <ESC>:call InsertHtmlTag()<CR> 

這就需要你有你的~/.vimrc:filetype plugin on。有關更多信息,請參見:help filetypes

相關問題