nickspoons / vim-cs

Official Vim Runtime Files for C#
9 stars 3 forks source link

Indent Issue in C# #68

Closed KiLLeRRaT closed 1 year ago

KiLLeRRaT commented 1 year ago

Hi,

I'm having some issues with indents in C#.

Settings are:

set autoindent
set smartindent
set expandtab
set tabstop=2
set shiftwidth=2

set cino? 
" cinoptions=

When I use gww to format a long line of C#, this happens:

Orig line:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IOutgoingEmailService outgoingEmailService)
{

Formatted line (pipes inserted where tab characters display for visibility):

public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
|  |  ILoggerFactory loggerFactory, IOutgoingEmailService
|  |  outgoingEmailService)
    {

It indents using two tabs, instead of a single tab.

Any thoughts on this?

Thanks,

nickspoons commented 1 year ago

This is standard indentation, see :help cino-(:

default 'shiftwidth' * 2

To have a "single" indent, use:

" ~/.vim/after/ftplugin/cs.vim
setlocal cinoptions=(1s
KiLLeRRaT commented 1 year ago

Hi @nickspoons , ah that's great and works~

Hmm there are quiet a few to iron out I think. I just stumbled upon another one:

return new LoginResponse
{
|  Success = false,
|  |  |  |  Message = _frameworkSettings.InvalidLoginErrorMessage
};

Do people mostly just ignore all this and manually deal with these issues as they write code, or do people just avoid using gg=G when working with C# files?

Thanks,

nickspoons commented 1 year ago

I don't know what other people do, I quite like the double-indent in an argument list that you originally described, it separates the declaration from the method content. That's a personal preference situation though.

The second one is handled with :help cino-J, so you'd include this like so:

" ~/.vim/after/ftplugin/cs.vim
setlocal cinoptions=(1s,J1

(1s is subjective but J1 is possibly something that should be pre-set by the C# runtime files.

nickspoons commented 1 year ago

J1 is possibly something that should be pre-set by the C# runtime files.

I had a quick search through the vim runtime files and no other runtime files set cino=J1 (except for some tests) so I won't do it here either.

nickspoons commented 2 months ago

Note: We now set then J1 cinoptions option.