Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding label indenting in C++

I guess this was asked before, but I could not find any similar question.

When writing part of the scope operator in C++, Vim guesses that it's going to be a label (on the first :) and then indents it automatically, which is pretty annoying. Example:

#1 - initial typing

{
    std

#2 - added :

{
std:

#3 - added :

{
    std::

Of course, it's correct at the end, but is there any way to disable the automatic indent for labels? I rarely use them, and it wouldn't be a great deal to indent manually in those cases.

like image 396
sidyll Avatar asked Jun 24 '11 17:06

sidyll


People also ask

Is indentation required in C?

1 The indent Program. The indent program can be used to make code easier to read. It can also convert from one style of writing C to another. indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax.

Can Ifdef be indented?

Liberal blank lines and comments are the approach I've typically taken regarding non-indented #ifdef checks. All that said, there's no rule that you can't indent preprocessor checks if it makes the code more readable.

How do I format C?

Step 1 Boot to system repair disc. After changing boot sequence in bios and restart computer, after which computer will boot from the system repair disc. Step 2 Click Command Prompt from System Recovery Options. Then type command format c: /fs:ntfs and press Enter key.

How many spaces is an indent when coding?

Software programs may use different amounts of indentation. However, a good rule of thumb is to use one space for each tab character in a line of code. Most computer programs use eight spaces to indent a line.


1 Answers

Just tell vim not to de-indent labels with:

:set cinoptions+=L0

For reference, if by "visibility" modifiers you mean access specifiers, these can be set to not indent with:

:set cinoptions+=g0
like image 196
CB Bailey Avatar answered Nov 15 '22 23:11

CB Bailey