Vim syntax highlighting disabled on certain files - vim

I have syntax highlighting enabled within my .vimrc file. Most files load with syntax highlighting working from start. Other files (with same extensions) will open without syntax highlighting on. I then set :syntax on and it works, but i have to do it every time i open that particular file. I've searched for answers but nothing has worked for me.
Frustrated. Ideas?

Related

How to add Syntax Highlighting in Vim for .ini files

I recently started using Vi Improved and being a Rainmeter Skin Specialist, when editing my .ini files I can't find a way to add syntax highlight for such files. I searched for a lot of time on stack and git and turned up to nothing. Requesting help at the latest.
TLDR; Need .ini file syntax highlighting for Vim
Vim already has syntax highlighting for *.ini files.
If your Vim is reasonably recent, say 8.0 and up, and you didn't set anything up with regards to Vim (no $HOME\_vimrc, nothing), then your *.ini files should be highlighted without any human intervention at all.
The screenshot below was taken in a test VM with a basic Vim without any setup:
If you have already customised Vim, with a $HOME\_vimrc file and/or with a $HOME\vimfiles directory, then you are in full control, which means that the automatic stuff described above is no longer done for you anymore. And being in full control of Vim pretty much requires that you learn it properly and configure it as you go.
Having EITHER of the following lines in your $HOME\_vimrc or $HOME\vimfiles\vimrc is going to give you automatic syntax highlighting for any recognised filetype:
syntax enable
syntax on

How to re-enable syntax highlighting in Vim?

Vim language highlighting has quit working only for one specific file.
I've been using Vim in WSL (Ubuntu) for several months now without problems. My PC is Windows 10 Professional. Strangely, Vim is no longer highlighting properly when I open a particular file. Everything works fine with every other file, but if I open this one file, it does not display correctly. The language highlighting is gone. Line numbers, tabs, and end-of-file-tildes still follow the color scheme, but my actual code is simply colored white. Does anyone know how to fix this?
More details:
The file type is *.v
If I rename the file, it displays correctly.
If multiple files are open at once (i.e. split view), every other file displays fine while this one file does not.
The problem arose in the middle of a work session, and I changed nothing in the vimrc before the problem arose.
After seeing the problem, I ran apt-get update and apt-get upgrade, followed by a restart.
I tried changing the color scheme in my vimrc.
Nothing I tried worked. Any ideas or insight would be greatly appreciated. Thanks!
EDIT: This question will be moved to vim.stackexchange.com
I have one mapping to toggle syntax, maybe it will help you
nnoremap <silent> <expr> <Leader>s exists('g:syntax_on') ? ':syntax off<cr>' : ':syntax enable<cr>'

Vim syntax doesn't highlight in real time

I have enabled vim syntax on (in ~/.vimrc syntax on) and it works but only on files with a code in when I view them. When I create a new file with vim and write there some code - no syntax highlight. After saving this file and reopening with vim - syntax highlight works perfect.
I am using manjaro KDE.
When you open a new file without an extension (vim mynewfile) none of vim’s filetype detection mechanisms can recognize it (they all use either extensions or first-couple-of-lines heuristics, which don’t work here).
When you enter code and reopen the file, the line-checks for filetypes work, causing the syntax to be set correctly, causing highlights to apply.
You can always set syntax=mine (though set filetype=mine is better) to set it manually.
This problem shouldnt happen when you do vim some.c or similar, because the extension will force detection based on extension rules.
Vim must know how to highlight your syntax in order to actually highlight it. One way to do this, is for Vim to check the file name and sometimes inspect the contents of the file, and set the file type. The file type is then used to highlight the syntax.
To enable detection of the file type (and load plugin and indent files), add the following to your vimrc:
filetype on plugin indent
If Vim is unable to detect the file type, and you have not yet saved your file with a known extension, you can set the file type manually, like this:
:set filetype=html
Vim will then highlight the syntax of the file as HTML syntax.
More information is available in the help pages.

Vim directory with macvim/terminalvim

I am using mac vim in terminal via /Applications/MacVim.app/Contents/vim
By now I didn't really care about what was in the MacVim directory in /Applications/MacVim.app/Contents/Resources/vim/runtime
and still somehow I had proper syntax highlighting etc.. I guess my vim loaded the files from macvim?
Somehow I messed arround with snipmate and all the syntax highlighting stopped to work. Filetypes are correct, but no highlighting. So I copied the syntax folder from the macvim app to my ~/.vim/syntax and it worked like a charm. Is there a way how I can use the ones from the app again?
Thanks for any help
Copying the syntax to your own ~/.vim/ directory effectively forks the factory-defaults. The downside is that you now have to update your copy whenever Macvim is updated.
The key to figuring out the problems is the 'runtimepath' setting. By modifying that (in your ~/.vimrc), you should be able to include the proper runtime files (and that is not just syntax, but also filetype plugins, should you have :filetype plugin on). BTW, it's unlikely this is caused by snipMate.
:set runtimepath?
Also, the :scriptnames command tells you exactly which scripts have been sourced so far.

Syntax Highlighting in VIM after :bd

When I useVIMthe syntax highlighting works, except after I return to a buffer using:bdthe highlighting disappears. I can enable it again using:syn on.This problem occurs only for files without an extension. I remember I had to change some settings to get files without an extension to be highlighted in the first place, but I can't remember the details. (I use files without an extension because thegfcommand just works when I do this.) Can anyone help?
Thanks.
take a look at :h modeline you should be able to set a comment in the file that tells vim what settings to use when you visit that file.

Resources