Neovim Indent Bug? - vim

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.

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?

VIM filetype plugin does not take expandtab option

Here's my .vimrc what I expect is expandtab to work on every mentioned
filetype, except make where it is explicitly disabled. et used to work as a non-filetype set command, but detecting the filetype is important.
" vundle Config
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'vim-syntastic/syntastic'
Plugin 'Shougo/vimproc'
" All of your Plugins must be added before the following line
call vundle#end()
filetype on
filetype plugin on
filetype indent on
" Remove whitespace
autocmd BufWritePre * %s/\s\+$//e
autocmd FileType cpp,html,css set et paste tabstop=4 shiftwidth=4 backspace=2 matchpairs+=<:>
autocmd FileType haskell,go,js,erlang,vim,tex set et paste tabstop=4 shiftwidth=4 backspace=2
autocmd FileType make set noexpandtab paste shiftwidth=8 softtabstop=0
syntax on
What I observe is that some options are set, some are not. The expandtab is the one that I can't get to work specifically. Here's the output of :set when opening my .vimrc file (filetype=vim).
backspace=2 filetype=vim keywordprg=:help paste shiftwidth=4 tabstop=4 ttymouse=sgr
commentstring="%s helplang=en laststatus=2 scroll=21 syntax=vim ttyfast
Ah, that's a tricky one. Have a look at :help 'paste':
When the 'paste' option is switched on (also when it was already on):
mapping in Insert mode and Command-line mode is disabled
abbreviations are disabled
'autoindent' is reset
'expandtab' is reset
[...]
Note how the option is introduced:
This is useful if you want to cut or copy some text from one window and paste it in Vim.
This option only is meant to be temporarily enabled when pasting into the terminal. Usually via a key configured in the 'pastetoggle' option. (GVIM doesn't need it; it can detect pastes. If you have X selection and clipboard enabled, you can also use the * and + registers instead.)
additional comments
The three :filetype commands can be condensed into a single filetype plugin indent on.
If you put this around your :autocmds, you'll remove the risk that some plugin clobbers them, and you can also safely reload your ~/.vimrc without defining duplicates:
augroup myCustomizations
autocmd!
autocmd ...
augroup END

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

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.

Transitioning to vim. Having issues with indentation

I am recovering from a surgery, thusly, I am transitioning to VIM. As I starting point, I've opted to use the vim-sensible plugin as the foundation of my configuration. Additionally, I've installed the 'vim-rails' and 'vim-ruby' plugins. These are all loaded via Pathogen.
For whatever reason, the plugins are not adjusting indentation settings in accord with filetype. Tabs seem locked to 9 columns. I am able to set them manually, but obviously this is not ideal.
Here is my .vimrc. As you can see, it is very basic.
execute pathogen#infect()
syntax on
filetype plugin indent on
Vim provides the following buffer local options for managing indention: 'softtabstop', 'shiftwidth', 'tabstop', and 'expandtab'. The idea is to set these options for a specific filetype, e.g. ruby either by using an autocommand or using the after ftplugin directory (my preference).
After directory approach
Add the following to your ~/.vim/after/ftplugin/ruby.vim file:
setlocal softtabstop=2
setlocal shiftwidth=2
setlocal tabstop=2
Autocommand approach
Add the following to your ~/.vimrc file:
augroup MyIndentSettings
autocmd!
autocmd FileType ruby setlocal softtabstop=2 shiftwidth=2 tabstop=2
augroup END
Learn more
As you are just starting to vim it is best to learn how to query these options so you can track down future bugs. Querying an option is as simple as :verbose set {option}?, e.g. :verbose set expandtab?.
You may also be interested in Tim Pope's vim-sleuth which heuristically sets indent settings.
For more help see:
:h :set
:h 'softtabstop'
:h 'shiftwidth'
:h 'tabstop'
:h 'expandtab'
:h after-directory
In my vimrc I have the following:
set autoindent
set expandtabs
set shiftwidth=4
set tabstop=4
Actually I just have
set ai et sw=4 ts=4
You can change the specific settings using FileType or BufEnter:
autocmd BufEnter *.py ai et sw=4 ts=4

Resources