我正在努力使用.vimrc来根据文件类型应用特定的配置。遵循autocmd FileType建议here,我尝试应用基于文件类型的配置。以下是我的.vimrc中的内容:
autocmd FileType tex call Tex_config()
function Tex_config()
let g:LatexBox_viewer = 'skim'
let g:LatexBox_latexmk_options = '-pvc'
let g:tex_flavor = "latex"
setlocal spell spelllang=en_ca
endfunction我可以使用以下命令调用函数Tex_config():调试Tex_config: Vim愉快地通过该函数。因此,一切看起来都应该可以正常工作。
但是,当我发出:set filetype=tex命令时,奇怪的事情发生了:拼写检查关闭。当我发出:set filetype=foo命令时,拼写检查就会打开。这与我期望从这个配置片段中发生的事情正好相反!
任何帮助都将不胜感激。这是完整的vimrc (44-50的函数)。谢谢。
发布于 2011-06-01 06:20:34
不要将.vimrc用于文件类型特定的东西,Lynch为文件类型或情景vimrc设置描述了一种令人难以置信的精确机制。
例如:我的.vim中的一些东西
.vim/ftdetect:
haml.vim macports.vim puppet.vim
hiveminder.vim markdown.vim ruby.vim
.vim/ftplugin:
haml.vim portfile.vim sshconfig.vim
html_snip_helper.vim python.vim tmux.vim
javascript.vim python_match.vim zsh.vim
markdown.vim sass.vim
plist.vim scss.vim在我的sshconfig.vim文件中(我设置了"K“,在我光标所在的标题处给出了sshconfig的手册页。太棒了,那个把戏。)
" sshconfig ftplugin.
" At this point, only want to set man as the keywordprg
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
" Customizations for sshconfig files
" what I _want_ is to jump to the heading
set keywordprg=man\ ssh_config\ -P\ \'less\ -p\ <cword>\'现在,在.vim/ftdetect/macports.vim中,我有代码来确定这个文件是否是Portfile
" Portfile
au BufNewFile,BufRead Portfile set filetype=portfile
au FileType portfile compiler portfile我应该把编译器portfile拉出来放到ftplugins中,因为你可以看到这个系统会变得多么疯狂,但这就是ctag和git的用处。
发布于 2011-04-24 01:10:56
您可以将特定命令添加到.vim/ftplugin/tex.vim。然后,Vim将自动识别tex是一种文件类型,并从您的tex.vim加载其行为。
例如,我将其用于手册页.vim/ftplugin/man.vim:
setlocal nolist
setlocal nomod
setlocal nonumber
" Set scratch buffer"
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile确保在vimrc中有下面这行代码来设置vim文件夹:
let $VIM='~/.vim/'https://stackoverflow.com/questions/5751928
复制相似问题