0

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?

David Hahn
  • 740
  • 9
  • 26
  • Have you tried putting the syntax file in ~/.vim/syntax? You shouldn't need to set up autocommands. I realize that isn't quite what you asked, but might help. – Codie CodeMonkey Jan 10 '13 at 18:20
  • First, you should get a plugin manager like Vundle. Second, you don't really need to setup the auto commands. Third, if you use Vundle or similar you will not need to source the files manually. – greduan Jan 10 '13 at 18:44
  • Also, if you don't want to use Pathogen or Vundle then atleast put it in the correct folder, which would be `~/.vim/indent` and `~/.vim/syntax`. – greduan Jan 10 '13 at 18:45
  • Your last comment worked for me. Thanks – David Hahn Jan 10 '13 at 20:05

1 Answers1

0

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324