Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: alignment of public keyword

Tags:

c++

vim

d

Currently, vim aligns my public:s like so:

class foo {
  public:
     void bar();
}

Which is to say, 2 spaces before public: and then a full tab (which is three spaces in my case) after it.

How would I get it to align thus:

class foo {
 public:
   void bar();
}

As in the void bar(); is indented at exactly one tab (three spaces), and the public: is sort of "halfway" (or one spaces in)?

like image 806
Infiltrator Avatar asked Dec 26 '22 18:12

Infiltrator


1 Answers

C++ indention defaults to cindent and as such can be tweaked by setting cinoptions. To get the indention you ask for, do this:

set cinoptions+=g1,h2

See :help cino-g and :help cino-h.

As mentioned in the comments cino-g and h do not always work, an alternative is :help cinoptions-values which leads to the same list. :help indent.txt is also useful.

like image 96
Thor Avatar answered Jan 05 '23 17:01

Thor