1

I'm using filetype indent on in my vimrc, generally this works very well, when pressing return it sets the indentation properly (in most cases).

However it has a very strange/annoying behavior, of re-indenting a line, when editing some text to that line. eg, editing a CMakeLists.txt, typing endif( will re-indent the the line based on vims indentation logic (in other cases too, this is just an example).

Is there a way to enable filetype indent when adding in new-lines, but not have it attempt to re-indent existing text while typing?

2
  • 1
    In addition to filetype indent, the settings of fo (formatoption) modifies vims indent behaviour. I would check the settings with :set fo? Nov 9, 2015 at 13:57
  • I'm curious: Is there a reason why you have not marked my answer as correct? Perhaps I am wrong (I do not think so)? Nov 16, 2015 at 21:02

1 Answer 1

2

You can modify the indent behaviour through the option indentkeys. The docs explain things relatively well:

A list of keys that, when typed in Insert mode, cause reindenting of the current line. Only happens if 'indentexpr' isn't empty. The format is identical to 'cinkeys', see |indentkeys-format|.

If you do: :echo &indentkeys, you will see that the filetype plugin for cmake adds for instance ENDIF(. Thus you might want to do something like:

set indentkeys&

To reset the option to its default value. Note that this should come in $VIM/after/ftplugin/cmake.vim (or similar) so that it is sourced after the regular filetype plugin.

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.

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