Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何调用vimrc中的函数取决于文件类型_Vim - Fatal编程技术网

如何调用vimrc中的函数取决于文件类型

如何调用vimrc中的函数取决于文件类型,vim,Vim,我在vimrc中有一个函数。该函数用于在html中完成标记 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

我在vimrc中有一个函数。该函数用于在html中完成标记

 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>
42函数!InsertHtmlTag()

43让pat='\cVim允许特定于文件类型的配置。将代码段从
~/.vimrc
移动到例如
~/.vim/ftplugin/html\u inserttag.vim
,并将映射缓冲区设为本地:

inoremap <buffer> > <ESC>:call InsertHtmlTag()<CR>
inoremap>:调用InsertHtmlTag()
这要求在
~/.vimrc
中有
:文件类型插件。有关更多信息,请参阅
:帮助文件类型