0

When opening a C file, then even with the vanilla setup on my Linux Mint system, if I type identifier at the beginning of an indented line and then ':' immediately after it, the indentation for that line gets deleted.

How can I disable this behavior?

Petr Skocik
  • 251
  • 2
  • 11
  • 3
    Does this answer your question? How do I debug my vimrc file? – Matt Feb 06 '21 at 10:38
  • @Matt Nice of you to be so condescending. I had done HOME=$PWD vi testfile.c in an empty directory so I'm pretty sure it's not a problem of debugging my (empty) .vimrc. But this cindent option is pointing me in the right direction, so thanks! ;-) – Petr Skocik Feb 06 '21 at 10:50
  • 3
    cindent must not be set by default. Setting HOME=$PWD is wrong, as it still allows processing /usr/share/vim and such. That is, your problem is broken installation / altered runtime files. – Matt Feb 06 '21 at 11:17
  • @Matt The system files are exactly as they came from the package manager of my system (which might not be vanilla enough for some definitions of the word). The vim -u NONE -U NONE -N recommended in the link you posted works to suppress the behavior, though. Useful info. Thank you. – Petr Skocik Feb 06 '21 at 11:34
  • 2
    This is strange, since cindent should not be enabled for non-C filetypes, only C filetypes and a few very similar languages (where this is expected, as text: is treated as a label). Are you sure there's no vimrc file in ~/.vimrc or ~/.vim/vimrc? Or maybe there's a plugin or something in the ~/.vim/pack directory? On which system are you using Vim? Maybe they ship with a weird non-standard configuration? You can also check where it was set with :20verbose set cindent, and see which files are loaded with :scriptnames. – Martin Tournoij Feb 06 '21 at 14:24
  • 1
    The command to check where it was set is :20verbose set consent?, with the ? asking to query what the option is set to and the :verbose asking where it was set. – filbranden Feb 06 '21 at 15:36
  • @MartinTournoij Thanks. With an empty .vimrc-less $HOME, it only happened with C files and :20verbose set cindent? showed /usr/share/vim/vim80/indent/c.vim as the culprit (I guess that's what my system, Linux Mint 19.3, provides). Textfiles were only affected with my real .vimrc, which also had set cindent in it. – Petr Skocik Feb 06 '21 at 15:48
  • Ah right, so you do have a vimrc file then? I'm a bit confused because before you said it's empty? At any rate, don't add that in your vimrc: it's only intended to be set for specific filetypes such as C. Then you don't need to frob with cinkeys either. This setting is very old and goes back to before Vim had a generic indentation system. – Martin Tournoij Feb 06 '21 at 23:36

1 Answers1

2

My vanilla vim setup (empty .vimrc) had the cindent option on an the related cinkeys option set to (the default) cinkeys=0{,0},0),:,0#,!^F,o,O,e.

Removing the : from the list disables the reindenting behavior associated with :.

More info is available with :help 'cindent'.

Thanks to Matt for pointing me in the right direction!

Petr Skocik
  • 251
  • 2
  • 11