简体   繁体   English

源〜/ .vimrc在文件中工作,但不会自动源咖啡

[英]source ~/.vimrc working in file but not automatically source coffee

I have added the coffee syntax and indent plugin for vim. 我为vim添加了coffee语法和缩进插件。 Here is my ~/.vimrc: 这是我的〜/ .vimrc:

colorscheme peachpuff
syntax on
filetype on
source /Users/(myusername)/.vim/vim-coffee-script-master/indent/coffee.vim
source /Users/(myusername)/.vim/vim-coffee-script-master/syntax/coffee.vim

au BufNewFile,BufRead *.js set filetype=javascript
au BufNewFile,BufRead *.coffee set filetype=coffee
au BufNewFile,BufRead *.rake set filetype=ruby
au BufNewFile,BufRead *.rb set filetype=ruby
au BufNewFile,BufRead Gemfile set filetype=ruby
au BufNewFile,BufRead Guardfile set filetype=ruby
au BufNewFile,BufRead *.less set filetype=scss

set autoindent
set expandtab
set softtabstop=2
set shiftwidth=2

This doesn't have the syntax highlighting when I open a .coffee file. 当我打开.coffee文件时,语法没有突出显示。 I then run :so ~/.vimrc while I am in the file and the syntax highlighting appears. 然后,当我在文件中时,运行:so ~/.vimrc并显示语法高亮。 Also, when I split the screen and run :so ~/.vimrc in one window it disappears in the other. 另外,当我分割屏幕并在一个窗口中运行:so ~/.vimrc ,它在另一个窗口中:so ~/.vimrc消失。 Any ideas? 有任何想法吗?

The .vimrc file is for global settings. .vimrc文件用于全局设置。 By sourcing coffee -specific scripts in there, you only temporarily apply them to the bare Vim during startup; 通过在其中采购特定于咖啡的脚本,您只能在启动过程中将它们临时应用到裸Vim。 any files you open aren't affected by it. 您打开的所有文件均不受此文件的影响。

Instead, Vim has an elaborate mechanism for detecting various types of programming languages and other file types; 相反,Vim具有精心设计的机制来检测各种类型的编程语言和其他文件类型。 cp. cp。 :help filetypes . :help filetypes Syntax files should be placed into ~/.vim/syntax/ and indents into ~/.vim/indent/ . 语法文件应放在~/.vim/syntax/ ,缩进到~/.vim/indent/ Then, once you :setf coffee (or if there is a detection defined for *.coffee ), it'll all be automatically activated. 然后,一旦您:setf coffee (或者如果为*.coffee定义了检测),它将全部被自动激活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM