2011-04-22 85 views
0

我很努力使用.vimrc來應用基於文件類型的特定配置。在autocmd FileType建議here之後,我試圖應用基於文件類型的配置。以下是我在我的.vimrc:Vim配置特定的文件類型

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的愉快spets通過該功能。所以,一切似乎都應該起作用。

但是,當我發出:set filetype=tex時發生了一些奇怪的事情:拼寫檢查關閉。當我發出:set filetype=foo拼寫檢查打開。恰恰與我期望通過此配置代碼段發生的事情相反!

任何援助將不勝感激。這裏是完整的vimrc(功能在44-50)。謝謝。

+0

我看到你在使用病原體。在一個可能不相關的說明中,如果您的系統範圍vim設置在病原體運行之前打開它,您可能希望在調用病原體功能之前關閉'filetype plugin'。我不認爲這是造成你的問題,但它是病原體的好習慣。 – 2011-04-22 13:09:01

回答

2

您可以將特定命令添加到.vim/ftplugin/tex.vim。然後Vim會自動識別出tex是一個文件類型並從tex.vim加載它的行爲。

例如我用這個手冊頁的.vim /文件類型插件/ man.vim:

setlocal nolist 
setlocal nomod 
setlocal nonumber 

" Set scratch buffer" 
setlocal buftype=nofile 
setlocal bufhidden=hide 
setlocal noswapfile 

請確保您有這條線,在vimrc設置你的vim文件夾:

let $VIM='~/.vim/' 
5

不要將.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手冊頁與標題我的光標在。Sofaking好,那招。)現在

" 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中,因爲你可以看到這個系統會如何瘋狂,但這就是ctags和git的用處。