Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim does not apply some settings from .vimrc

Tags:

vim

My .vimrc has a string "set tabstop=4", but it doesn't apply when i open something, for example, python file. Here's my full .vimrc:

cnoremap Q q
au! BufWritePost .vimrc source %
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4
set autoindent
"set syntax=off
set t_co=256

strace says vim reads /home/user/.vimrc, and he really reads this file, for example, cnoremap works, he replaces :Q by :q as expected, but if i, for example, uncomment set syntax=off, it does not apply. Also, vim -V2 says next:

...
считывание сценария "$HOME/.vimrc"
Поиск "syntax/off.vim syntax/off/*.vim" в "/home/user/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/home/user/.vim/after"
not found in 'runtimepath': "syntax/off.vim syntax/off/*.vim"
...

Of course, i thought, it was something with options. But if i made in editor :so $MYVIMRC, he applies all settings!

Right now i live with bash alias vim="vim -S ~/.vimrc", and in verbose mode he applies .vimrc without errors and works as expected, but that's weird solution.

What could be wrong here? And why vim does not apply tabstop/syntax from .vimrc?

Output of :verb set ts

tabstop=8
        В последний раз опция изменена в /usr/share/vim/vim80/ftplugin/python.vim

Output of :scriptnames

1: /etc/vimrc
  2: /usr/share/vim/vim80/syntax/syntax.vim
  3: /usr/share/vim/vim80/syntax/synload.vim
  4: /usr/share/vim/vim80/syntax/syncolor.vim
  5: /usr/share/vim/vim80/filetype.vim
  6: /usr/share/vim/vimfiles/ftdetect/dockerfile.vim
  7: /usr/share/vim/vimfiles/ftdetect/nginx.vim
  8: /usr/share/vim/vimfiles/ftdetect/stp.vim
  9: /usr/share/vim/vim80/ftplugin.vim
 10: ~/.vimrc
 11: /usr/share/vim/vim80/plugin/getscriptPlugin.vim
 12: /usr/share/vim/vim80/plugin/gzip.vim
 13: /usr/share/vim/vim80/plugin/logiPat.vim
 14: /usr/share/vim/vim80/plugin/manpager.vim
 15: /usr/share/vim/vim80/plugin/matchparen.vim
 16: /usr/share/vim/vim80/plugin/netrwPlugin.vim
 17: /usr/share/vim/vim80/plugin/rrhelper.vim
 18: /usr/share/vim/vim80/plugin/spellfile.vim
 19: /usr/share/vim/vim80/plugin/tarPlugin.vim
 20: /usr/share/vim/vim80/plugin/tohtml.vim
 21: /usr/share/vim/vim80/plugin/vimballPlugin.vim
 22: /usr/share/vim/vim80/plugin/zipPlugin.vim
 23: /usr/share/vim/vim80/syntax/python.vim
 24: /usr/share/vim/vim80/ftplugin/python.vim
like image 970
Igor Ovsyannikov Avatar asked Jul 10 '17 11:07

Igor Ovsyannikov


2 Answers

If the output of the command :verbose set tabstop? in a python buffer is:

tabstop=8
        В последний раз опция изменена в /usr/share/vim/vim80/ftplugin/python.vim

It means that the filetype plugin /usr/share/vim/vi80/ftplugin/python.vim sets the value of your 'tabstop' option, local to the current python buffer, with 8 while you want 4.

Your setting set tabstop=4 doesn't take effect in a python buffer, because a local value has priority over a global one.

If you want to override this, you could create the file ~/.vim/after/ftplugin/python.vim and write inside:

setlocal tabstop=4

Or you could add the following autocmd inside your vimrc:

augroup my_python_settings
    autocmd!
    autocmd FileType python setlocal tabstop=4
augroup END
like image 98
user852573 Avatar answered Oct 12 '22 00:10

user852573


You may have the issue referred here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864074

The solution is to uncomment the following line in /etc/vim/vimrc (by removing the " at the beginning of the line):

let g:skip_defaults_vim = 1

For me it was the set mouse=a which forced the Visual mode in vim 8.0, and didn't in vim 7.4.

like image 43
Yvan Avatar answered Oct 12 '22 01:10

Yvan