Vim: use tabs for indentation, spaces to align with C source files

Does anyone have her vim setting that uses hard tabs as indentation but uses spaces for alignment? The problem is that when starting the continuation line, as in

if (condition1 && (anotherlongcondition || /* <-- Here I insert a newline */ |-------|------- whatever /* some additional alignment added automatically */ 

then cin (which is necessary for me) adds some tuning as I prefer positionally , but this alignment is created using as many hard tabs as possible and filling the rest with spaces (as I tried to render).

So, in short, cin doesn't really highlight indentation and alignment . I would really like all the added alignment in the example above to be spaces. Thus, the alignment will be saved correctly when temporarily switching ts .

To clarify this again, I would like to write the following code without pressing <TAB> or <SPACE> before the first non-empty character on any line (and without performing any manual switching or anything else):

 void foo(int bar) { |-------somestatement; |-------if (somecondition && (someothercondition || |------- whatevercomesnext)) |-------|-------dosomething; } 

I already tried ctab.vim , but it focuses on editing the alignment line with soft tabs, which seems silly to me, because manual alignment is a task that provides a 1-step refinement rather than a step width step. I have not changed the way cin uses mixed tabs and spaces for alignment.

I could not find any built-in way to do this. Maybe one more? In any case, I doubt that there is a plugin. Although, I admittedly, I am not a vim-script myself and, perhaps, do not have enough experience, I must say that most of the plugins that I tried only spoiled my editor configuration ...

+7
source share
2 answers

Ok, sorry for the question. I finally found some good stuff for this.

http://vim.1045645.n5.nabble.com/Indent-with-tabs-align-with-spaces-td1183279.html

To summarize, currently vim is not flexible enough to be comfortable.

My :set cinoptions=(1 is :set cinoptions=(1 , which adds only one alignment block when starting the continuation line. That way, I can be sure that the added alignment is a space (until I :set ts=1 , at least ) and add a small amount of spaces manually. This is still okay in terms of speed and seems to be the least distracting behavior for me!

+1
source

In addition to yours: set cino = (1, you might also be interested in the "preserveindent" and "copyindent" options if you haven't met them yet. They don't completely solve your problem, but they go to the side of help.

+3
source

All Articles