Konrad Höffner
Konrad Höffner

Reputation: 12207

autocmd not applied from ~/.vimrc

How can I get my vim to apply the autocmd without manual reloading of ~/.vimrc? And why is the ... Filetype tsv ... never applied at all?

My ~/.vimrc

set ts=10
autocmd BufWrite * :echom "Writing buffer!"
autocmd Filetype tsv set ts=20 sts=20 sw=20

~/.vimrc is loaded, however the autocmd is applied only after a :so:

$ vim /tmp/test.tsv
:verbose set ts
  tabstop=10
    Last set by ~/.vimrc
:w
"test.tsv" 2L, 37C written
:so ~/.vimrc
:w
Writing buffer!
"test.tsv" 2L, 37C written

Also, why is the tabstop not set to 20 even though I edit a .tsv file?

vim --version: VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 11 2015 08:43:46)

:scriptnames:

  1: /etc/vimrc
  2: /usr/share/vim/vimfiles/archlinux.vim
  3: ~/.vimrc
  4: ~/.vim/plugin/InsertXSDDateTimeLiteral.vim
  5: ~/.vim/plugin/RdfNamespaceComplete.vim
  6: /usr/share/vim/vimfiles/plugin/SyntaxFolds.vim
  7: /usr/share/vim/vimfiles/plugin/filebrowser.vim
  8: /usr/share/vim/vimfiles/plugin/imaps.vim
  9: /usr/share/vim/vimfiles/plugin/libList.vim
 10: /usr/share/vim/vimfiles/plugin/remoteOpen.vim
 11: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
 12: /usr/share/vim/vim74/plugin/gzip.vim
 13: /usr/share/vim/vim74/plugin/logiPat.vim
 14: /usr/share/vim/vim74/plugin/matchparen.vim
 15: /usr/share/vim/vim74/plugin/netrwPlugin.vim
 16: /usr/share/vim/vim74/plugin/rrhelper.vim
 17: /usr/share/vim/vim74/plugin/spellfile.vim
 18: /usr/share/vim/vim74/plugin/tarPlugin.vim
 19: /usr/share/vim/vim74/plugin/tohtml.vim
 20: /usr/share/vim/vim74/plugin/vimballPlugin.vim
 21: /usr/share/vim/vim74/plugin/zipPlugin.vim

Upvotes: 1

Views: 2741

Answers (1)

edi9999
edi9999

Reputation: 20544

For the filetype problem, it is probably because vim doesn't know about the "tsv" file type : you can check that by running :set filetype which will return you the current filetype. (It returns "" for me on a *.tsv file)

The following will work for all *.tsv files

autocmd BufEnter *.tsv set ts=20 sts=20 sw=20

Fot the other problem, it must be one of your plugins or other things in your .vimrc overwriting this (because it works with only those three lines in the vimrc). Try to find the culprit by running :autocmd which will list all registered autocommands

Upvotes: 2

Related Questions