At the moment I use :syntax off for markdown. But I'd like to make it syntax off when I edit a markdown file.
I tried this in .vimrc but md files has syntax.
"""""syntax off for markdown"""
if &ft=='md'
syntax off
else
syntax on
endif
How can I do it?
You can accomplish it with an auto-command for all buffers for which the filetype is set to "markdown", or "md", like so:
autocmd Filetype markdown setlocal syntax=OFF
You can read about the syntax of commands Vim can execute automatically with :help :autocmd.
I got the answer from here.
Create ~/.vim/after/syntax/markdown.vim with:
setlocal syntax=
Related
I tried spell check for text file by adding this to my vimrc
augroup set_spell
autocmd!
autocmd FileType text :setlocal spell spelllang=en_us
augroup END
nnoremap <F10> :setlocal spell! spelllang=en_us<CR>
And it did not work
I tried :set spell and nothing happened
For some reasons, when I ran :source $MYVIMRC (still in that window), it worked. Though I can add sourcing command to my vimrc but I don't like the glitchy feeling of it.
What am I supposed to do?
Edit: I have found the solution
It's the problem with this vim rainbow plugin
https://github.com/frazrepo/vim-rainbow
So I uninstall that one and install this instead https://github.com/luochen1990/rainbow
Open the file and immediately do a :set ft? and :set spell?. Make sure they return text and spell respectively. If text is not returned, then the filetype is not being detected. If text is returned but spell is not, then the autocommand is not working.
Additionally, you should wrap autcommands in an augroup. See :h autocmd-groups. It might look like this:
augroup set_spell
autocmd!
autocmd FileType text setlocal spell
augroup END
Because this is a FileType autocommand, you are probably better off skipping the augroup and autocommands altogether and just putting the line setlocal spell in an ftplugin file. It would normally go in ~/vim/ftplugin/text.vim.
As a more general solution: Sometimes theme plugins overwrite SpellBad highlight group(It's one those gui vs terminal problems). Even though spell check works it just doesn't highlight. Without deleting your theme you can just add more style to the SpellBad highlight group as you wish:
Simply add this to your .vimrc:
"underline spell errors in terminals
hi SpellBad cterm=underline
or any other style really:
hi SpellBad ctermfg=Cyan cterm=bold
Be warned, these do not overwrite all existing styles. To truly overwriting it you may need to use hi clear SpellBad first.
See :h highlight for all the details. For the other Spell groups see :h hl-SpellBad.
I want to apply a Vim autocmd to all source code files -- for instance,
autocmd FileType <code> :set tw=80
Can I do this without listing all the different extensions exhaustively, like
autocmd FileType ruby, python, python3, java ... :set tw=80
What's the best way to do this? Is there some general FileType or Syntax that Vim recognizes inside any source file?
You can use * to match all occurrences of an event. In your case:
:autocmd FileType * command
See :help autocmd-patterns and :help file-pattern.
I have syntax highlighting enabled in .vimrc, but that makes loading certain files too long. So I need to disable (or, to be precise, not enable... enabling it and then disabling is not a solution) syntax highlighting for these files. I tried
au BufNewFile,BufRead !*.inc syntax enable
but that made just no syntax highlighting applied ever. The solution presented here does not work for me, since I can't make a distinction by filetype. I tried adapting to no avail, which might or might not be connected to the events needed for "syntax enable".
Thanks for any pointers!
The mentioned solution points to the right direction: Define an autocmd for all buffers, and then (instead of 'filetype'), match with the filename via expand('<afile>'):
au BufNewFile,BufRead * if expand('<afile>:e') !=? 'inc' | syntax enable | endif
Here, I've used your example of *.inc extensions in the condition. If you find the matching cumbersome and would rather use the autocmd syntax, you can do that with an intermediate buffer flag, too, using the fact that autocmds are executed in order of definition:
au BufNewFile,BufRead *.inc let b:isOmitSyntax = 1
au BufNewFile,BufRead * if ! exists('b:isOmitSyntax') | syntax enable | endif
If you want to show syntax only for .c files. Put
syntax off
autocmd! bufreadpost *.c syntax on
in your vimrc.
Also you can map a key for enabling syntax (Ctrl+s in this case)
nnoremap <C-S> :syntax on<CR>
In you question you want to disable syntax only for .inc file. Do it like this:
syntax on
autocmd! bufreadpost *.inc set syntax=off
To disable syntax highlighting for files with .inc extension, you can basically use:
syntax on
au BufNewFile,BufRead *.inc setlocal syntax=OFF
To disable it for multiple extensions, e.g. also for py:
au BufNewFile,BufRead *.{inc,py} setlocal syntax=OFF
I want spell checking to be enabled on vim when editing .txt or .md files. I added
setlocal spell spelllang=en_au
to .vimrc but that did spell checking for everything.
This might be doable with an autocmd though I've never tried it:
autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en_au
autocmd BufNewFile,BufRead *.md setlocal spell spelllang=en_au
Well, try to enable spell check directly in vim, not ~/.vimrc
:set spell
Does it work?
spcific language spell check may not work in some cases.
This would be what you need in _vimrc.
set spell spelllang=en_us
I have installed Markdown syntax plugin.
When I'm on a new buffer not associated with any file, and paste the source portion of the site http://rosylilly.github.com/markdown.html into it, the colors appear nicely as it should for the markdown syntax.
However, after saving the file, the colors change. Any idea how I can fix this?
Can you, before and after saving do
:verbose set filetype
:verbose set
Tip: use :redir > file.txt to capture the output so you won't have to copy/paste which can be difficult with gvim - for command output
You could also look at the autocommands when saving:
:verbose au BufWrite
:verbose au BufWritePre
:verbose au BufWritePost
This would serve to discover what plugin/script is causing the highlighting to go haywire.