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+=_
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.
Here's my ~/.vimrc on some machine:
set softtabstop=0 noexpandtab nosmarttab
set shiftwidth=4
set tabstop=4
colorscheme murphy
... but when I edit files, tabs show up as 8 spaces, and typing in a tab produces for spaces. I looked around and found this question:
set expandtab in .vimrc not taking effect
but I don't have set paste in my ~/.vimrc, so that can't be the problem. What's causing this? And how can I enforce my tab preferences?
Edit: It seems my settings are only ignored for some filetypes, not for simple text files. How can I force my settings to apply to all filetypes? Or at least to specific types?
Solution for a specific file type (rather than for all file types):
For file type foo Add the following to your ~/.vimrc:
augroup foo
autocmd!
autocmd FileType foo setlocal softtabstop=0 noexpandtab nosmarttab shiftwidth=4 tabstop=4
augroup END
and replace foo with the file type in both occurrences.
Note: foo is not necessarily a file extension. For example, the Python language (.py typically), file type is python.
I use Vim 7.3, and have this in my .vimrc (and nothing else):
filetype plugin indent on
autocmd FileType java :setlocal sw=4 ts=4 sts=2 noet
autocmd BufNewFile,BufReadPost ~/testdir/* setlocal sw=2 ts=2 sts=2 et
I have a directory ~/testdir which only contains a subdirectory p and the file ~/testdir/p/A.java which contains this:
class A {
}
If I open A.java by saying :e ~/testdir/p/A.java then :set et? reports that expandtab is currently ON.
On the other hand, if I start a new instance of Vim and go :vim A ~/testdir/** then this search will open A.java, but now :set et? tells me expandtab is OFF.
How do I make my intended indentation settings always apply for files under ~/testdir/?
The event BufReadPost should be being fired. Check that writing a message. This is:
autocmd BufNewFile,BufReadPost $HOME/git/repo/* echom "Reading buffer " . expand("<afile>")
Look for the messages with:
:messages
If the messages are there, then you know you are setting those options for the buffer. So, if the options have changed when the buffer is displayed, perhaps a plugin is setting them to some other thing. Check who is the culprit by showing who last changed the option with
:verbose set sw?
If that doesn't lead you to a solution, try using BufWinEnter instead of BufReadPost. That would probably work.
Vim explicitly recommends using ~ for the user home.
The help at :h autocmd-patterns says that you can use environment variables in the event patterns ...
... [a]nd ~ can be used for the home directory (if $HOME is defined):
:autocmd BufWritePost ~/.vimrc so ~/.vimrc
:autocmd BufRead ~archive/* set readonly
The environment variable is expanded when the autocommand is defined, not when
the autocommand is executed. This is different from the command!
So, change $HOME to ~ in your autocommand.
Even if your problem turns out to be unrelated it's good to follow the practice recommended in the docs.
The autocmd does work but probably not the way you expect since you did not set softtabstop.
autocmd BufNewFile,BufReadPost ~/git/repo/* setlocal sw=2 ts=2 sts=2 et
If you do not set softtabstop it will keep its old value. If this value is not 0 (which seems to be the case) when you press tab you will get the number of softtabstop spaces inserted into the file. And it will look like its not working.
It is generally a good idea to set shiftwidth, tabstop, and softtabstop to the same value if you ever change it.
Its also probably a good idea to make the set command local to the buffer by using setlocal.
Take a look at :h softtabstop
You can see that the autocmd "works" when softtabstop is set to its default value (of 0) if you run the command like this. And then run your :vim command
vim -u NONE -N -c'autocmd BufNewFile,BufReadPost $HOME/git/repo/* set sw=2 ts=2 et'
For some reason, Vim keeps using soft-tabs (tabs as spaces) everytime I'm working on Haml files. I prefer regular tabs and have the following in my vimrc:
set autoindent
set noexpandtab
set tabstop=4
set shiftwidth=4
Which seems to work great for every file type except for Haml. When editing Haml files Vim uses two spaces rather than a tab, any suggestions as to how this can be reverted back to my default settings (ie. regular tabs)?
It was because the indent script for haml sets expandtab for you automatically when VIM has detected the current file is in haml format. The script is located at $VIMRUNTIME/indent/haml.vim. It contains:
setlocal autoindent sw=2 et
To disable that, you can put this line in your ~/.vimrc to clear the expandtab setting again:
au! FileType haml set noet
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.