2

I don't get it, my vimrc has set ai, but when editing project files (php), :set ai? always returns noautoindent

inside .vimrc :set ai? returns true.

my rc:

" vim-plug (https://github.com/junegunn/vim-plug)
" Automatically install vim-plug and run PlugInstall if vim-plug not found

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

"*****************************************************************************
"" Plug install packages
"*****************************************************************************

" Specify a directory for plugins
call plug#begin('~/.vim/plugged')

Plug 'tyrannicaltoucan/vim-quantum' " let g:quantum_black = 1
Plug 'ctrlpvim/ctrlp.vim'
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'airblade/vim-gitgutter'
Plug 'bronson/vim-trailing-whitespace'
Plug 'editorconfig/editorconfig-vim'
Plug 'Raimondi/delimitMate'
Plug 'scrooloose/syntastic'
Plug 'Yggdroot/indentLine'
Plug 'tpope/vim-commentary'
Plug 'sheerun/vim-polyglot'
Plug 'valloric/matchtagalways' " doesn't work properly in neovim, cursor jumps about
Plug 'ap/vim-buftabline'
Plug 'ConradIrwin/vim-bracketed-paste'

" Initialize plugin system
call plug#end()

"*****************************************************************************
"" Visual Settings
"*****************************************************************************

set number
set ruler
set nowrap

if $TERM_PROGRAM =~ "iTerm"
  set termguicolors
endif

let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

let g:quantum_black = 1
colorscheme quantum

"*****************************************************************************
"" NERDTree config
"*****************************************************************************

let NERDTreeShowHidden = 1
let NERDTreeIgnore=['.git$[[dir]]', '.swp']

map <C-n> :NERDTreeToggle<CR>

"*****************************************************************************
"" Optimizations
"*****************************************************************************

set lazyredraw

let g:python_host_skip_check = 1
let g:python3_host_skip_check = 1

"*****************************************************************************
"" syntastic
"*****************************************************************************

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

"*****************************************************************************
"" yank and cut to osx clipboard
"*****************************************************************************

noremap YY "+y<CR>
noremap XX "+x<CR>

"*****************************************************************************
"" indent
"*****************************************************************************

" tabs
set listchars=tab:˗\ ,eol:¬
set list

" spaces
let g:indentLine_enabled = 1
let g:indentLine_concealcursor = 0
let g:indentLine_char = '·'
let g:indentLine_faster = 1

set tabstop=2
set softtabstop=2
set shiftwidth=2

set ai

filetype plugin indent on

" make < > indents keep selection
vnoremap < <gv
vnoremap > >gv

"*****************************************************************************
"" matchtagalways
"*****************************************************************************

let g:mta_filetypes = { 'html' : 1, 'xhtml' : 1, 'xml' : 1, 'jinja' : 1, 'php': 1 }

"*****************************************************************************
"" ctrlp
"*****************************************************************************

set wildignore+=*.o,*.obj,.git,*.rbc,*.pyc,__pycache__
let g:ctrlp_custom_ignore = '\v[\/](node_modules|target|dist)|(\.(swp|tox|ico|git|hg|svn))$'



"*****************************************************************************
"" buffers
"*****************************************************************************

noremap <Tab> :bnext<CR>
noremap <S-Tab> :bprevious<CR>

noremap <C-w> :bd<CR>

"*****************************************************************************
"" general
"*****************************************************************************

set autoread
set backspace=indent,eol,start

" :h last-position-jump
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

2 Answers 2

5

This is because of vim's internal php settings. If you look in vim##/indent/php.vim, there's the following line:

setlocal noautoindent

If you want to override this feature, you'll need to use an autocmd in your vimrc. Try this:

autocmd FileType php setlocal autoindent

This will turn on auto indenting whenever vim detects it's editing a php file. Alternatively if you want to always have autoindenting, you could also do this:

autocmd BufReadPost * setlocal autoindent

This will turn on auto indenting whenever vim open any file.

It's probably worth noting that if they specifcally turned off autoindent they may have a good reason for it. But this is how you would change it if you wanted to.

For more info see :h autocmd

3
  • 2
    Since the BufReadPost event occurs before the FileType event, I think that the BufReadPost autocommand may not work as it will be followed by the sourcing of the indent/php.vim file. (I have not tested that.) It might be better to use autocmd FileType * setlocal autoindent instead. It is true that that will not be triggered if the filetype is not set, but in that case, no filetype plugins will be sourced to mess up your preferred autoindent setting, either.
    – garyjohn
    Jan 18, 2017 at 0:18
  • wait that makes no sense. how I see: vim comes php-indent script, this script disables system ai in favor of its own implementation. So the problem is that indent/php.vim doesn't work for some reason.
    – user10804
    Jan 18, 2017 at 6:11
  • @salivan You didn't actually ask about php indenting though. You specifically asked what was switching off the autoindent option. You'll need to update your question if your problem is actually with how Vim's default PHP indenting works. (Or better, write a new one, which would avoid moving the goalposts after Tumbler41 has already answered)
    – Rich
    Jan 18, 2017 at 9:56
2

The general mechanism for discovering where a particular Vim option was set is the :verbose command:

:verbose set autoindent?

The above will inform you that autoindent was most recently unset by the script in location $VIMRUNTIME/indent/php.vim

@Tumbler41 has already described how to overrule this with an autocommand, but I'll note that Vim also has more specific mechanisms for altering settings made by a global filetype plugin, which are described in :help ftplugin-overrule.

In your case, the third method is the the best one to use:

Create a file in the location ~/.vim/after/indent/php.vim with the contents:

setlocal autoindent
1
  • thx for :verbose set autoindent? this is useful
    – user10804
    Jan 18, 2017 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.