Before introducing the octave syntax file in ~/.config/nvim/syntax/octave.vim from here auto-indent worked as expected.

After introducing the file, the syntax coloring works, but the auto-indentation does not.

I already read this remarks and it looks like it should be working.

Does anyone knows what I can do to get auto-indent to work?

  • Welcome to Vim :-) Could you precise what you mean by working? Could you give us example of auto indentation you had and miss? I'm also interested by the following information. Remove the lines you introduced in init.vim to get Octave coloring, restart Neovim and give us the result of the following commands :set ft? and :set autoindent? :set cindent? :set indentexpr? Feb 27, 2023 at 6:08
  • 1
    :set ft -> filetype=matlab
    – notabot
    Feb 27, 2023 at 6:54
  • Thanks :-) That is what I was expecting (see my answer). Feb 27, 2023 at 6:55
  • Hi thank you. For example, when I do gg=G I expect the whole document to be formatted. Or say I have a for-loop and I press return, I expect the cursor to start in the next line tabbed over by 1. filetype=matlab :set autoindent #returns itself :set cindent #returns itself indentexpr=GetMatlabIndent()
    – notabot
    Feb 27, 2023 at 7:03
  • Thanks for the result but I believe you miss the ? in my command. The consequence is that you set the option (and then it returns itself). Could you restart Neovim and repeat the commands with the trailing ? included? I'm already 99% convince that you had matlab auto-indentation that is indeed relatively good for Octave although probably not 100% perfect. Feb 27, 2023 at 7:09

2 Answers 2


I believe your problem is not related to the Octave syntax file. It only introduces syntax coloring properties.

I believe the problem comes with the lines that associate the octave file type to the buffers corresponding to the *.m and *.oct files:

augroup octavedetect
  au! BufRead,BufNewFile *.m,*.oct set filetype=octave
augroup END 

By default *.m files are associated to the matlab file type and come with the matlab auto-indentation.

With the new lines the octave indentation is reset to your Neovim default indentation.

You can restore it to the matlab indentation with the following lines into your init.vim:

augroup octavetype
  au! BufRead,BufNewFile *.m,*.oct setlocal indentexpr=GetMatlabIndent()
augroup END 

Or by adding an octave.vim file into ~/.config/nvim/ftplugin/ with the following content:

setlocal indentexpr=GetMatlabIndent()

But maybe should we search for a more Octave specific auto-indentation.

Maybe could you consider installing the following plugin octave that bring both colorization and Octave specific auto-indentation?

  • I just downloaded the plugin with Plug. The syntax highlighting and auto-indentation seems to be working perfectly! Thanks for your suggestion! :)
    – notabot
    Feb 27, 2023 at 7:37
  • You are welcome! If you are fine with the solution could you validate it using the v green button next to the arrow voting buttons. It helps the question to rest :-) Feb 27, 2023 at 7:43
  • Never mind what you suggested did not solve the problem. I tried each suggestion. When I changed indentexpr to GetMatlabIndent() indentation simply does nothing (breaks formatting completely). When I use the plugin the formatting algorithm doesn't know where: if, for, while etc end, so it keeps on tabbing indefinitely over instead of knowing where the end of the loop is. If you have any suggestions it would be appreciated. I have a couple more things to try, Ill update if I figure it out.
    – notabot
    Mar 16, 2023 at 20:27

rik: At least for Vim, syntax and indentation are two different things handled by two different scripts. I wrote the syntax highlighter for Vim (which should reside in ~/.vim/syntax) and I also wrote an indenter for Vim which which should reside in ~/.vim/indent. The indent file is octave.vim and is attached here. You can probably get it to run on NeoVim easily.


Syntax file from: octave.vim : Syntax highlighting file for GNU Octave language

Anyone with this issue please see the following thread: https://octave.discourse.group/t/neovim-octave-syntax-highlighting-and-indentation/4228


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.