cindentationneovimauto-indent

How to enable Neovim's indentation for C files


Indentation works perfectly for Java and Python, but not C:

GIF demonstrating pressing Enter in between braces does not auto-indent

init.vim file:

set mouse=a
set encoding=utf-8
set number
set noswapfile
set scrolloff=7
set backspace=indent,eol,start
set clipboard+=unnamedplus

set signcolumn=yes

set fileformat=unix
filetype plugin indent on

" for tabulation "

set tabstop=4
set shiftwidth=4
set nosmartindent
set expandtab
set noautoindent
set wrap

" updatetime for vim-gitgutter "
set updatetime=100

let g:loaded_perl_provider = 0
let g:loaded_ruby_provider = 0
let g:loaded_node_provider = 0

" Set shiftwidth for different file extensions "
autocmd FileType javascript setlocal shiftwidth=2
autocmd FileType javascriptreact setlocal shiftwidth=2

" Java indentation settings "
augroup filetypedetect
  au BufRead,BufNewFile *.java setfiletype java
augroup END

autocmd FileType java setlocal shiftwidth=4
autocmd FileType java setlocal tabstop=4
autocmd FileType java setlocal softtabstop=4
autocmd FileType java setlocal expandtab

" C indentation settings "

" Set syntax highlight for .tsx and .jsx files "
autocmd BufNewFile,BufRead *.tsx,*.jsx set filetype=typescriptreact

set t_Co=256
let mapleader = ' '

" autoremove trailing whitespaces "
autocmd BufWritePre * :%s/\s\+$//e

inoremap jk <esc>

...

-- Treesitter config
local configs = require("nvim-treesitter.configs")
configs.setup {
  ensure_installed = {
    "typescript",
    "tsx",
  },
  sync_install = false,
  ignore_install = { "python", "vim" }, -- List of parsers to ignore installing
  highlight = {
    enable = false, -- false will disable the whole extension
    disable = { "python", "typescript", "tsx", "vim" }, -- list of language that will be disabled
    additional_vim_regex_highlighting = true,
  },
  indent = { enable = true, disable = {} },
}

...

How can I solve this?


Solution

  • I had to add C to Treesitter's list of languages. There were no problems with indentation settings.