I like the c.vim plugin, but I don't use the K & R code style

When I write code, I would like to use the ANSI C style, but the code style in the c.vim template is K & R.

Where can I get another template or any other plugin instead of c.vim ?

+7
source share
2 answers

You should check :help cinoptions-value and define your own C style.

IIRC, you need to set cindent to take cinoptions into account.

FWIW, this is what I do when opening a C or h file:

 setlocal cinoptions={0,:1s,g1s,t0,(0,=.5s setlocal noautoindent setlocal nosmartindent setlocal cindent 
+6
source

There is a great program called Artistic Style or Astil that does a whole bunch of code formatting for you. You can tell if you want space around the operators by opening curly braces on the same line as the loops, how you want to back off, etc. I tell you a little more about this: Automatic format C. It is easy to use, but the options allow you to customize a huge number of coding styles, including some predefined definitions for common styles, such as K & R.

Basically, once you install it in vimrc, just type gggqG to reformat your file. (gg to go to the beginning, gq to start formatting, G so that it is fully formatted to the end.)

This does not help formatting during your code, but it can be a life saver when working with an existing file that is not formatted correctly, or quickly clear your own code.

+4
source

All Articles