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.
Related
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+=_
I have delimitMate installed for brace completion in Vim but it is running for all files, not just .h and .cpp files. DelimitMate has an option for disabling itself in the buffer so I need to add something to my .vimrc that says "disable delimitMate in the buffer of all files except for .h and .cpp files" though I have no idea how to do that.
Reading the DelimitMate documentation at :h 'b:delimitMate_autoclose'. Add the following to your ~/.vimrc:
let g:delimitMate_autoclose = 0
augroup my_delimitmate
autocmd!
autocmd FileType cpp let b:delimitMate_autoclose = 1
augroup END
The idea is to turn off autoclose globally (g:) and turn it back on for specific buffers (b:).
Instead of the :autocmd and :augroup commands you can set b:loaded_delimitMate inside the appropriate ftplugin file. Example add the following to ~/.vim/after/ftplugin/cpp.vim:
let b:delimitMate_autoclose = 1
This method might be prefered if you want to keep your ~/.vimrc file clean or you already have many filetype specific commands, settings, or mappings.
Note: I do not use DelimitMate so I have not tested any of these settings.
For more help see:
:h :aug
:h :au
:h FileType
:h 'b:delimitMate_autoclose'
:h delimitMateFileType
:h ftplugin
I think what you are looking for is autocommands. Autocommands can run pieces of vimscript whenever a certain event happens. You can see a list of all possible events by doing :help autocmd-events
So according to your needs, first you should disable delimitMate in your vimrc. Then, you can put something like this in your vimrc (after you disable delimitMate):
autocmd FileType cpp (insert command to disable delimitMate here)
That way, vim will disable delimitMate by default, but it will enable it if the fieltype is cpp. (this includes header files)
Of course, more information is available on the autocmd command by doing :help :autocmd
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.
I turned on filetype plugin for some rails vim plugins I added, but a side effect of this seems to be that now autocommenting has been enabled in all filetypes (for instance, if I start a line with #, the next line, either by Enter in insert mode or O, etc. to enter insert mode, will also get a #).
I found a guide to disabling the auto-commenting formatoptions, and added the following to my .vimrc:
au FileType * setlocal formatoptions-=cro
However, I am still running into problems -- unless I explicitly :source .vimrc, (or enter the setlocal ... directly), it is not taking effect. I determined that this is the case because vim's ftplugins are overriding my options with their own.
I then found a second guide which talks about using an after ftplugin script to make changes after the ftplugin scripts have run, however their solution is to create symlinks for every single filetype in ~/.vim/after/ftplugin to a central file, and this seems to be kludgy to me.
Is there any way to create a generic after-ftplugin script or am I approaching this problem incorrectly? Any help would be appreciated.
How about an "after" plugin? Create a file in ~/.vim/after/plugin/ called noAutoComments.vim (or whatever) and place your autocmd in that?
Edit:
The reason this works? I'm only guessing here, but I have a feeling that the autocmd in the ~/.vimrc file is getting removed by some other file (but before the "after" files are getting sourced).
I ended up removing my ~/.vim directory and replaced my ~/.vimrc with the following 3 lines:
filetype plugin on
syntax on
au FileType * setlocal formatoptions-=cro
With only these lines in my ~/.vimrc and no ~/.vim/ directory, the autocmd seems to work as expected (Vim 7.1).
For any file that I edit:
:verbose set formatoptions?
formatoptions=ql
Last set from ~/.vimrc
I have yet to determine what file (plugin) is causing this issue however.
I've done some more investigation and it seems that the location of my autocmd within my .vimrc file determines if formatoptions will be overridden by vim's ftplugins or not. Using vim --noplugin to disable all external plugins, I found the following results:
If my vimrc looks like:
au FileType * setl fo-=cro
filetype plugin indent on
The result of :verbose set fo? is:
formatoptions=croql
Last set from /usr/share/vim/vim72/ftplugin/ruby.vim
However, if the lines in my vimrc are reversed:
filetype plugin indent on
au FileType * setl fo-=cro
The result of :verbose set fo? is:
formatoptions=ql
Last set from ~/.vimrc
... which is the desired result. So it seems that the autocmd needs to be specified after filetype plugins are enabled.
Another reason this might not be taking effect...
From :he :set-=:
When the option is a list of flags, {value} must be
exactly as they appear in the option. Remove flags
one by one to avoid problems.
I have
" Turn off auto-commenting
au FileType * setlocal formatoptions-=c
au FileType * setlocal formatoptions-=r
au FileType * setlocal formatoptions-=o
because I've run into this.
Using one of the various autocmd events to set the configuration option should work if you find the right one, but I'd start by running:
:verbose set formatoptions?
This will tell you where the option was set, which may make it easier to determine which autocmd to use. Alternatively, if you don't mind a bit of minor hacking, the way I'd probably do it is just to find out where it's set in the plugin and comment out that line (and make a note of it in case you ever upgrade the plugin). You could also contact the plugin's author and ask them to make it a configurable option.
For the available autocmd events, read this:
:help {event}
I have tried solutions proposed by many, but none of them worked for me, but I found one very simple workaround, namely, in your ~/.bash_aliases:
# vim without auto comment
alias vi="vi +'set fo-=cro'"
I was struggling with this issue and I finally works with the following lines:
syntax on
filetype on
filetype plugin on
au FileType * setlocal formatoptions-=cro
I think the key here is that the autocmd is place after the filetype plugin on.