vim set spell in any file - vim

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.

Related

How to set ft=antlr4 in vim? autocmd not working

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.

vim: open file and enable autoread in one command

G'day!
I have log file ~/log.txt and want to open it with vim and enable autoread option ( that makes vim reload file on change ) in single command.
I don't want to enable autoread manually with
:set autoread
I don't want to change .vimrc because I want autoread work only for log file.
Thank you!
You can tell Vim in your .vimrc file to add settings only to specific files.
autocmd BufNewFile,BufRead /home/foo/log.txt setlocal autoread
This autocommand will enable autoread automatically as soon as you open the log file.
Type :help :autocmd for an in-depth documentation of autocommands.

Vim autocompletion word with character _ , in python and latex

In vim, I managed to have autocompletion installing Supertab.
When I work on a .py file, it works ok: I can autocomplete xxx_yyy by typing xxTAB (and it pops up options if many xxx_yyy1 xxx_yyy2 exist).
But on a .tex file, if I have already the word xxx_yyy, when I type xxTAB I get the only match xxx.
How can I match xxx_yyy with xxTAB in a .tex file too?
This is my .vimrc :
filetype plugin indent on
syntax on
set backspace=indent,eol,start
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4
set ww=<,>,[,]
SuperTab uses the built-in insert mode completion (:help i_CTRL-N), and that is based on keywords. This setting is filetype-specific, controlled by the 'iskeyword' option. For Python, the _ is included, for Latex, it isn't (and based on #Konrad Rudolph's comment, for a reason).
You can certainly adapt this if it bothers you. In your ~/.vimrc:
autocmd Filetype tex setlocal iskeyword+=_

What exactly happens when you change a file type in vim?

If I have an apache file in /etc/apache2/sites-available/www.example.com and I set its filetype like so
:set filetype=apache
What does that do? Does that change the file at all? Is it only reflected in the instance of vim? The session of vim? I can manually set the filetype, but then vim warns me that I am in read only mode (/etc/apache2 needs root access). If I open vim as root, I won't get the warning, but if I leave and open it again (as normal or root), the filetype is gone. How do I make this more permanent, at least when called from the same session file
set filetype changes the way vim handles the file, by invoking all the FileType autocommands. It does not persist. If you want to always open that file with filetype=apache, try adding this into your .vimrc:
au BufRead,BufNewFile /etc/apache2/sites-available/www.example.com set filetype=apache
You can read more about it in:
:help 'filetype'
:help filetypes
:help :autocmd
:help .vimrc
EDIT: as found in my /usr/share/vim/vim73/filetype.vim:
au BufNewFile,BufRead access.conf*,apache.conf*,apache2.conf*,httpd.conf*,srm.conf* call s:StarSetf('apache')
au BufNewFile,BufRead */etc/apache2/*.conf*,*/etc/apache2/conf.*/*,*/etc/apache2/mods-*/*,*/etc/apache2/sites-*/*,*/etc/httpd/conf.d/*.conf* call s:StarSetf('apache')
s:StarSetf will setfiletype to apache if the filetype doesn't match an ignored pattern. On my system, :echo g:ft_ignore_pat will show only archive file extensions as ignored. setfiletype does set filetype, but only once.
So, at least on my system, the pattern */etc/apache2/sites-*/* would catch your filename and make it an apache file.
The filetype basically lets Vim change settings for 'types of files'. The way it does this is by firing auto command for the FileType category when you change the filetype. This could potentially change your file if an auto command for FileType is applicable for your file (but generally plugin developers use it for r/o type changes that affect highlighting, and not the contents of the file).
If you are worried that setting the filetype is mucking with your file you can see what FileType autocommands exist by issuing the following command:
:au FileType
To setup your apache files to be apache filetypes you can put something like the following into your ~/.vimrc:
:au BufRead /etc/apache2/sites-available/* set ft=apache

vim file specific .vimrc

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

Resources