My ~/.vimrc contains the following line:
au BufNewFile,BufRead *.fsh,*.vsh setf glsl
My ~/.vim/syntax directory contains glsl.vim that works if loaded manually (:setf glsl in Vim), but it doesn't load automatically when editing a file with those extensions. How do I get syntax highlighting for those files automatically? Syntax highlighting works for other files as usual. My Vim version is 7.4 running on Linux Mint.
I don't think that line can be in your ~/.vimrc. Due to loading order, it may have to be in ~/.vim/filetype.vim instead. Try putting this into that file:
augroup filetypedetect
au BufNewFile,BufRead *.fsh,*.vsh setf glsl
augroup END
Related
I am using vim 8.1 on macOS (vim-plug for plugin management). I need to work with COOL files, so I manually downloaded the syntax file and put it in ~/.vim/syntax
I added the following line to my .vimrc in order to associate the .cl extension with COOL:
au BufNewFile,BufRead *.cl setf cool
However, when I load .cl files into vim, it fails to recognise the language.
:verbose set ft ?
yields:
filetype=lisp
Last set from /usr/local/Cellar/vim/8.1.0650/share/vim/vim81/filetype.vim line 875
Changing the .virmc line to:
au BufNewFile,BufRead *.cool setf cool
makes vim recognise the files as COOL.
What should I do in order to have .cl default to COOL instead of LISP?
Create the file ~/.vim/filetype.vim with the following content:
augroup filetypedetect
au BufNewFile,BufRead *.cl setf cool
augroup END
See :help new-filetype.
I'm trying to detect buck's TARGETS file as 'buck' files instead of 'python', which is the filetype vim's currently detecting for them.
I tried to add autocmd BufRead,BufNewFile **/TARGETS set filetype=buck to my .vimrc but it didn't seem to work.
What's the correct way to change a 'default' detected file type ?
Your autocmd is the way to go in principle; just omit the **/ in the pattern:
autocmd BufRead,BufNewFile TARGETS set filetype=buck
see :help autocmd-patterns
Ideally, you'd have this line in a .vim/ftdetect/buck.vim file
I am trying to get vim to recognize a filetype.vim file consisting of the following:
if exists("did_load_filetypes")
finish
endif
augroup autodetect
au! BufRead,BufNewFile *.ish setfiletype perl
augroup END
This file is in the directory ~/programs/vim
My .vimrc file contains the following line:
set runtimepath=~/programs/vim,$VIMRUNTIME
I checked that this line is being executed by typing ":set runtimepath?" The result is "runtimepath=~/programs/vim,/usr/share/vim/vim74".
But when I open a file such as ish.ish, the vim filetype variable is set to 'on'. When I open x.pl, the vim filetype variable is set to 'perl'.
I can fix the problem by copying (or moving) filetype.vim to the ~/.vim directory (without changing runtimepath). Why doesn't vim recognize filetype.vim in ~/programs/vim?
The 'runtimepath' option is meant to tell Vim where to look for "standard" *.vim files such as colorschemes and plugins. Try :echo &rtp in a clean Vim session to see what it should look like and read :help 'runtimepath'. By setting this option to a meaningless value you effectively make Vim unable to find those files and thus work correctly.
To add a specific directory to 'runtimepath', use the following syntax:
set runtimepath+=/path/to/directory
But what's the reason you'd want to use a non-standard directory for standard scripts? What's wrong with ~/.vim?
The most obvious way to tell Vim about a new filetype is to add these lines to your ~/.vimrc:
augroup autodetect
autocmd!
autocmd BufRead,BufNewFile *.ish set filetype=perl
augroup END
The cleanest way is to put this line in ~/.vim/ftdetect/ish.vim:
autocmd BufRead,BufNewFile *.ish set filetype=perl
The GLSL syntax highlighter http://www.vim.org/scripts/script.php?script_id=1002 works well. But it doesn't recognize .frag or .vert shader files that commonly begin with a line like #version 330. (This is on Ubuntu 12.04.2 LTS, everything up to date.)
With such a line, after loading the file one must manually type set syntax=glsl,
probably because /usr/share/vim/vim73/filetype.vim has
" Generic configuration file (check this last, it's just guessing!)
if ... getline(1)=~'^#' ... setf conf.
Why doesn't that get overruled by ~/.vimrc's au BufNewFile,BufRead *.frag,*.vert setf glsl? Is there a workaround short of blundering about in filetype.vim?
How can I stop vim from loading a syntax file automatically for certain file types? came close. Here's the workaround, a file ~/.vim/filetype.vim:
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
" Override filetypes for certain files
autocmd! BufNewFile,BufRead *.frag setfiletype glsl
autocmd! BufNewFile,BufRead *.vert setfiletype glsl
augroup END
I can enable syntax highlighting for a file that has an extension that is unknown to vim by doing the following
set syntax=c
Every time I switch tabs however, I have to renter the command. Is there any way to let vim know that a file with an extension .xyz should be coloured with C syntax?
Put this at the end of your .vimrc (I'm assuming you have autocommands enabled).
autocmd BufRead,BufNewFile *.xmlx set filetype=xml
In your home directory, create the .vim/ftdetect/xyz.vim:
au BufRead,BufNewFile *.xyz set filetype=c " to overrule an existing filetype
au BufRead,BufNewFile *.xyz setfiletype c " to set it only if no filetype has been detected for this extension
With autocommand. E.g.
au BufNewFile,BufRead *.xyz setf c
You can set it in the vim config file:
http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/