Command not allowed from exrc/vimrc in current dir or tag search
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
When opening a file with vim, you encounter errors like the following:
# vi myfile.txt
Error detected while processing /usr/share/vim/vim74/syntax/nosyntax.vim:
line 14: E12: Command not allowed from exrc/vimrc in current dir or tag search: au! Syntax
line 17: E12: Command not allowed from exrc/vimrc in current dir or tag search: augroup syntaxset
line 18: E12: Command not allowed from exrc/vimrc in current dir or tag search: au!
line 19: E12: Command not allowed from exrc/vimrc in current dir or tag search: au BufEnter * syn clear
line 20: E12: Command not allowed from exrc/vimrc in current dir or tag search: au BufEnter * if exists("b:current_syntax") | unlet b:current_syntax | endif
line 22: E12: Command not allowed from exrc/vimrc in current dir or tag search: au!
line 23: E12: Command not allowed from exrc/vimrc in current dir or tag search: augroup END
...
This may happen in the following situation:
- the file you are trying to edit is in /home/user/myfile.txt
- the file /home/user/.vimrc exists.
- you are logged in as 'root', not as 'user'.
- as root, $HOME is set to /root.
When you start vim, it will source /root/.vimrc then it will try to source the .vimrc in the current directory, i.e. /home/user/.vimrc.
Even though you are root and have the permission to edit the file, security settings in vim causes the warning to appear.
You can ascertain which files are being sources and processed when vim starts by using the -V flag. Study the output:
# vi -V myfile.txt
Solution 1) Do not edit the file as root. Edit it as a regular user.
Solution 2) cd .. ; vim user/myfile.txt
Solution 3) chmod 600 .vimrc # prevent other users from loading the .vimrc that does not belong to them.