Red Hat Bugzilla – Bug 99437
vim no longer autoindents C code
Last modified: 2007-04-18 12:55:46 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030701
Description of problem:
As shipped with Red Hat 9, vim no longer automatically sets cindent when editing
C code. This is different (and less desireable) from vim as shipped with all
previous versions of Red Hat, at least as far back as Red Hat 7.1, and I believe
much earlier. I am in shock that this has not been reported earlier... I'd
have expected people to have noticed, and to complain.
Note that if you are not seeing this, it is almost certainly because you have
something in your .vimrc which is enabling cindent (or one of the other
auto-indent features). Rename your .vimrc and any .vim directory, and you
should see the problem. Except, well, you shouldn't.
I identified where the problem is by perusing a recursive diff of
/usr/share/vim/vim61 on each of a Red Hat 8 and Red Hat 9 system. Doing so
reveals the following code which is present in RH8, but missing from RH9, which
when applied with patch -p1 fixes the problem:
--- RH9/macros/vimrc 2003-02-12 07:44:38.000000000 -0500
+++ RH8/macros/vimrc 2002-12-23 17:02:48.000000000 -0500
@@ -45,6 +45,44 @@
+ augroup cprog
+ " Remove all cprog autocommands
+ " When starting to edit a file:
+ " For C and C++ files set formatting of comments and set C-indenting on.
+ " For other files switch it off.
+ " Don't change the order, it's important that the line with * comes first.
+ autocmd FileType * set formatoptions=tcql nocindent comments&
+ autocmd FileType c,cpp set formatoptions=croql cindent comments=sr:/*,mb:*,e
+ augroup END
+ augroup gzip
+ " Remove all gzip autocommands
+ " Enable editing of gzipped files
+ " read: set binary mode before reading the file
+ " uncompress text in buffer after reading
+ " write: compress file after writing
+ " append: uncompress file, append, compress file
+ autocmd BufReadPre,FileReadPre *.gz set bin
+ autocmd BufReadPost,FileReadPost *.gz let ch_save = &ch|set ch=2
+ autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip
+ autocmd BufReadPost,FileReadPost *.gz set nobin
+ autocmd BufReadPost,FileReadPost *.gz let &ch = ch_save|unlet ch_save
+ autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " .
+ autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r
+ autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r
+ autocmd FileAppendPre *.gz !gunzip <afile>
+ autocmd FileAppendPre *.gz !mv <afile>:r <afile>
+ autocmd FileAppendPost *.gz !mv <afile> <afile>:r
+ autocmd FileAppendPost *.gz !gzip <afile>:r
+ augroup END
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. vim somefile.c
2. type code
3. notice lack of indenting
Expected Results: C code should be indented.
Setting these autocommands in /usr/share/vim/vim*/macros/vimrc would overwrite any
user settings. Please have a look at bug #84088 for an explanation why the autocommands
have been removed from the global vimrc.