简体   繁体   中英

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

I have added the coffee syntax and indent plugin for vim. Here is my ~/.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. I then run :so ~/.vimrc while I am in the file and the syntax highlighting appears. Also, when I split the screen and run :so ~/.vimrc in one window it disappears in the other. Any ideas?

The .vimrc file is for global settings. By sourcing coffee -specific scripts in there, you only temporarily apply them to the bare Vim during startup; 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; cp. :help filetypes . Syntax files should be placed into ~/.vim/syntax/ and indents into ~/.vim/indent/ . Then, once you :setf coffee (or if there is a detection defined for *.coffee ), it'll all be automatically activated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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