How to check which (Neo)vim syntax highlighting plugin is being used - vim

The title basically explains the gist of it. I am having some issues with my syntax highlighting, and I understand it is possible to check the filetype I am in currently with :setlocal syntax? and that I can check the specification of the highlighting with :syn list, but I am looking to see what plugin or native Neovim functionality is currently in control of syntax highlighting.

None of the :syntax subcommands works with :help :verbose-cmd, which is a tool commonly used for debugging mappings, commands, etc. So, without :verbose or a dedicated command, you are left with very fuzzy heuristics like:
$ vim foo.js
:filter syntax scriptnames
which shows what syntax scripts have been sourced in the current session:
6: ~/Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
7: ~/Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
8: ~/Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
64: ~/.vim/pack/lang/start/javascript/syntax/javascript.vim
65: ~/.vim/pack/lang/start/javascript/syntax/javascript/html5.vim
66: ~/Applications/MacVim.app/Contents/Resources/vim/runtime/syntax/javascript.vim
67: ~/.vim/pack/lang/start/javascript/after/syntax/javascript.vim

Related

How do I turn on vim syntax highlighting via modeline?

In my .vimrc file I have
syntax off
Suppose I want to turn on syntax highlighting on a case-by-case basis via vim's modeline? I've tried many combinations, like:
# vim: syntax on:
but I still can't get it to work. What do I need to do in the modeline?
According to :help syntax, using syntax enable or syntax on loads syntax files at runtime. But there's also apparently syntax manual which turns it on based on the syntax type you specify. Looking at the source vimscript, it says:
It installs the Syntax autocommands, but not the FileType autocommands.
You can therefore use syntax= to set the type, and that works in a modeline to either set a specific type or set none which effectively turns it off.
# vimrc
syntax manual
# In your files
# Turn it on for this yaml file
# vim: syntax=yaml:
# Or this PHP file
# vim: syntax=php:
If you want to be explicit about disabling it in a file:
# In your files
# No syntax highlighting for this file (default if omitted)
# vim: syntax=none:
Vim is a multi-buffer/window/tab editor. Changing global state (syntax, colorscheme, loading plugin etc.) per current file is a wrong habit. Luckily, modeline does not allow this.
What you can do in the modeline is to set :h local-options. Accidentally, there's an option also named :h 'syntax'. And it has the same syntax as any other option.
# vim: syntax=OFF
You don't need to set :syntax manual for this to work, as modeline has preference over filetype detection. However, if FileType event is fired manually (e.g. :setf xyz) while :syntax on then buffer's syntax could be redefined to match new filetype. Not a problem though.

Is 'Noh' different from 'noh' in Vim

I know that
:noh
is for "no highlight" - to remove highlighting in text.
Sometimes by mistake I type
:Noh
and it replaces something which I do not know and I have to do control-Z.
What does :Noh do in Vim?
Edit: With command :h Noh, I get help for noh only.
I get this:
:Noh
E492: Not an editor command: :Noh
Built-in commands (except :X) start with a lowercase letter; user-defined commands (via :command) must start with an uppercase letter. (The :help has a case-insensitive search fallback, that's why you've found the original built-in command.)
So, you have a custom :Noh command (or something that starts with these letters and is unique). What that is and where it was defined can be found out via
:verbose command Noh
If you wanted to know that it does (the "replaces something"), you could :debug Noh, or :20verbose Noh.

How do I start vim with syntax highlighting off?

How do I start vim with syntax highlighting off?
Vim is taking a long time to highlight syntax for large XML files for me.
You can start vim with
vim -c 'syn off'
Or you can specify that it should turn it off for large XML files by making an ftplugin file. For instance put
if getfsize(expand('%')) > 400000
syntax off
endif
in a file named ~/.vim/ftplugin/xml.vim
You need to disable syntax highlighting. You can do that (and few additional options that can be useful in such situation) by following this instruction on Vi SE.

Vim turn on syntax highlighting

I've been using Vim as my text editor, but now that I'm using it to write Python code, I'd like it to hightlight the syntax like this:
How do I turn on syntax highlighting in Vim? How do I get it to stay on by default for programming files?
Turning On Syntax Highlighting:
Open the file that you'd like to have syntax highlighting enabled for with vim filename.py.
Press esc, then type :syntax on and hit enter.
Syntax highlighting should now be enabled!
Note: This will only turn on syntax highlighting temporarily. In other words, if you quit working on that file and open it again, or open a different file with vim, syntax highlighting will be off by default. If you'd like to make syntax highlighting permanent, you need to do some extra steps.
Enabling Syntax Highlighting by Default:
Change directory to your home directory by typing cd into the terminal.
Type vim .vimrc, which will edit the .vimrc file if you have it, or create it if you don't.
Append syntax on to the file as a new line, then hit esc, type :wq, and hit enter.
Syntax highlighting will now be enabled by default for files ending in common programming language extensions such as .py.
If you would like to turn off the syntax highlighting for a particular file, you can do that on a case by case basis.
Turning Off Syntax Highlighting for a Specific File:
Open the file that you'd like to have synta highlighting disabled for with vim filename.py.
Press esc, then type :syntax off and hit enter.
Syntax highlighting should now be disabled!

Enabling markdown highlighting in Vim

I'm using Vim in a terminal on my MacBook Air with OS X Lion, and I can't seem to find a good plugin for Markdown syntax highlighting.
So far I've tried the plasticboy plugin and Tim Pope's plugin. The plasticboy plugin worked OK but was causing white space at the end of lines to be highlighted, and I haven't figured out how to turn that off. (It's really annoying, because every time I hit space when I'm writing it highlights the character.)
Tim's plugin didn't seem to do very much in the way of highlighting, other than maybe headers that use ###. Code blocks and bullets are ignored. I might be missing something there. I do use the .md extension on my Markdown files, so it should be picking up the filetype.
I've also seen a reference to Vim 7.3 having Markdown support built in, but without one of those two plugins I don't get any highlighting at all.
Do either of these require specific color schemes to work?
About the native syntax highlight for markdown I think it only works for files with the extension .markdown by default.
I was having problems with markdown syntax highlight for my .md files.
I tried:
:set syntax=markdown
And it worked.
So i included the following line in my .vimrc:
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
Now my vim have syntax highlight for my .md files.
BufFilePre is needed for :sav
Native syntax highlighting
Native syntax highlighting for Markdown only works by default for the .markdown file extension.
The following line in .vimrc yields the best results for both vim and gvim:
autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown.pandoc
Explanation:
1. Specify your Markdown flavour!
If you work with mainly one flavour of Markdown (e.g. Pandoc), be sure to mention this as well! Doing so, allows for mixing and matching of both Markdown- and Pandoc-specific Vim plug-ins. For example: I have found the vim-pandoc-syntax plug-in particularly suitable for my highlighting needs. Nevertheless, I use the more general vim-markdown-folding for Markdown folding.
By the way, only one flavour is allowed, separated by a dot, e.g.: filetype=markdown.pandoc
2. gvim requires BufFilePre
gvim requires an additional BufFilePre in the autocommand line for Markdown file type recognition with the Save As… :sav command.
This should work to disable the end-of-line space highlighting when using the plasticboy mkd plugin:
:syn clear mkdLineBreak
You could autocmd that for the necessary file extensions so that you needn't do it every time you load a markdown file.
Note that this specific highlight exists because Markdown treats lines ending with 2 or more space characters specially by inserting a <br>, so it is useful.
The plasticboy plugin uses TODO highlighting for this rule, which is a bit too much as it's designed to, by default, be really garish - yellow background - so that it stands out. You can make this less visually striking by changing that highlight rule. One quick way to do this would be something like:
:hi link mkdLineBreak Underlined
Now those end-of-line spaces will show up as underlined. Try linking to other highlight groups for something that may appeal to you more. Instead of using link you can get even more specific about those end-of-line spaces: for instance you could specify that they show up as just slightly lighter/darker than the normal background, using your own highlight command, specifying custom ctermfg, ctermbg, guifg, guibg settings.
As above, you could autocmd this to apply your specific settings.
For more information about link highlight groups, type: :help group-name and you'll see a list of groups that can be linked that themselves should helpfully be displayed using their current highlight rules. Also: :help highlight.
In Tim's plugin the .md extension works only for README.md because filetype.vim specifies so.
" Markdown
au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,README.md setf markdown
If you don't like putting all of your configuration in ~/.vimrc, you can create ~/.vim/ftdetect/markdown.md (or its equivalent on Windows) with the following contents.
au BufNewFile,BufRead *.md setf markdown

Resources