Why is c.vim overriding .vimrc for HTML? - vim

My ~/.vimrc contains the following (default in Ubuntu 14.04, just added the last line):
set smartindent
set tabstop=4
set shiftwidth=4
filetype plugin indent on
In ~/.vim/after/ftplugin/c.vim:
set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
I was expecting for only .c and .h files to use 8-column tabs. However, other files are also being afected such as .html files.
How can I make c.vim affect only C-related files?

Change this:
set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab
to this:
setlocal tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab

Related

My VIM configuration doesn't work with autocmd plugin

set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab
set nu
set autoindent
set cindent
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
filetype plugin indent on
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4
I added the last two lines into .vimrc but received this error message:
-bash: filetype: command not found
-bash: autocmd: command not found
I haven't used this plugin before and what's the proper way to enable it? My purpose is to avoid the error message when I edit a file with vim on a Linux machine remotely:
TabError: inconsistent use of tabs and spaces in indentation
-bash: filetype: command not found
-bash: autocmd: command not found
These errors seem to be printed by bash,
did you run something like source .vimrc?

don't apply current options to new opened file vim

I frequntly open many files in vim. The problem is some files have their own options. For example:
settings for make files
set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4
set list listchars=eol:¬,tab:→⠀,trail:~,extends:>,precedes:<
hi SpecialKey ctermfg=243
hi NonText ctermfg=243
settings for C files
set colorcolumn=100 tabstop=4 shiftwidth=4 softtabstop=4
So, if I open makefile first and then :tabe main.c I can see invisble character that were turned on from makefile.
I understand that I can :set nolist but imagine if I have many other options inherit from many other files. How can I tell vim not to inherit them when I :tabe anotherFile?
Well there is setlocal to set this things for a buffer only.
But that does of course not work for a .vimrc. There you have two possibilities, autocmds or filetype plugins:
autocmd BufRead,BufNewFile *.{c} setlocal colorcolumnt=100
This does set the settings local to any oppened buffer of a file ending with .c
Or you can add the settings to a filetype-plugin. See :h filetype-plugin for more information on that. Basically just add the settings to a specific file. In your case most likely under .vim/ftplugin/c.vim

Vim permanent syntax highlighting

I'm using :set syntax=javascript whenever I work on TypeScript files for example. I want to set the syntax automatically based on my file type. Now here's the thing, I've done it before by adding:
au BufNewFile,BufRead,BufReadPost *.ts set syntax=javascript
to my ~/.vimrc file, however, it doesn't seem to be working anymore.
Here is the contents of my .vimrc file. Is there a reason why this wouldn't work?
colorscheme atom-dark-256
set number
set autoindent
set guifont=monaco:h12
set expandtab
set tabstop=4 shiftwidth=4 expandtab
au BufNewFile,BufRead,BufReadPost *.ts set syntax=javascript
au BufNewFile,BufRead,BufReadPost *.handlebars set syntax=HTML
au BufNewFile,BufRead,BufReadPost *.twig set syntax=HTML
au BufNewFile,BufRead,BufReadPost *.theme set syntax=PHP
I'm sure it used to work just fine, but it just stopped for some reason. Any ideas? I'm using MacVim if that helps?
Let us set the filetype of *.ts as javascript so that it applies javascript syntax using
au BufEnter,BufRead *.ts set filetype=javascript

Neovim Indent Bug?

I have the following options in my .config/nvim/init.vim:
set tabstop=4
set shiftwidth=4
set expandtab
set ai
set smartindent
filetype on
filetype plugin on
filetype indent on
So, the indentation engine should work on all files, but it does not.
When I edit my config file for example, :set ai returns: autoindent and :set si returns: smartindent.
But when I run the same commands on a php file they return:
noautoindent
nosmartindent
EDIT:
The file that was overriding my config is:
/usr/share/nvim/runtime/indent/php.vim
It's the default php indent file.

How to set vim use tab instead of 4 whitespace?

"(1)use 4 whitespace instead of tab
set cindent
set smartindent
set autoindent
"set softtabstop=4 shiftwidth=4 expandtab smarttab
"(2)use tab instead of 4 whitespace
set cindent
set smartindent
set autoindent
set tabstop=4 shiftwidth=4 noexpandtab
The first settings is 4 whitespace.
Now my team use tab, the second setting work correctly in *.cpp *.h files, but still show 4 whitespace in *.py file.
I don't know why...?
Check this blog entry: http://henry.precheur.org/vim/python.html
Creating a proper file in ftplugin folder will recognize the options for any python file.

Resources