I've installed a syntax file at ~.vim/after/syntax/antlr4.vim. And it works great when I manually open a file and then type in:
:set ft=antlr4
However, for whatever reason I cannot get it to recognize the file in my .vimrc. Here is what I currently have, but it seems to be doing nothing:
" Antlr4 highlighting
au BufRead,BufNewFile *.g4 set filetype=antlr4
Move this line:
au BufRead,BufNewFile *.g4 set filetype=antlr4
into that file:
~/.vim/ftdetect/antlr4.vim
See :help ftdetect.
Related
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
so this is what my .vimrc contains, why is my syntax highlighting not working?
set nocompatible " must be the first line
filetype plugin indent on
syntax on
set laststatus=2
set statusline=%<%f\%h%m%r%=%-20.(line=%l\ \ col=%c%V\ \ totlin=%L%)\ \ \%h%m%r%=%-40(bytval=0x%B,%n%Y%)\%P
set nu
set shortmess=I
set nowrap
set tabstop=2
set backspace=indent,eol,start
set shiftwidth=2
set shiftround
set ignorecase
set smarttab
set hlsearch
set incsearch
set undolevels=1000
set pastetoggle=<F2>
set t_Co=256
colorscheme monokai
let g:user_emmet_leader_key = '<c-y>'
execute pathogen#infect()
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd vimenter * NERDTree
My color theme works, but the colors are not showing up properly as syntax highlighting.
Any suggestions?
First, check the output of:
:setlocal syntax?
The correct output (for php files) is:
syntax=php
You can check the php syntax code doing a:
:syntax list
You must see all syntax code with the command above. If you don't get the syntax=php value or don't see any syntax code on :syntax list, probably you don't have a php.vim file in your ~/.vim/ftplugin folder. When you set filetype plugin on and open an php file, what Vim does is to look in your ftplugin folder for a php.vim file and execute it.
php.vim is a system file, and it comes with the default installation. Try to do a :scriptname to see all scripts that are opening with vim. If you can't see a php.vim file, a solution could be install StanAngeloff/php.vim plugin.
If, and only if, you have a php.vim file and see its syntax with :syntax list, then something external is affecting Vim's syntax highlight, and it's probably your terminal.
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
in ~/.vimrc I have
au BufNewFile,BufRead *.tex,*.md,*.markdown set spell
but when I have open a this filetype file and after I open other file, example :
:sp ~/.vimrc
this get spell highlight.
Use :setlocal spell (or :setl spell, for short) to enable spelling locally
in the current window.
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/