2

I have applied C# formatter on vs code that helps me formatting on save automatically, but I don't know how to set it up so that it deletes empty lines like code maid does on visual studio. I want to be able to set up rules when formatting. But cant figure it out how to set up the json of that formatteer.

Is there any extension that helps out with this? I tried installing Beautify but is isn't compatible with C#.

For example, I want to be able to delete lines 39 and 40 in the following code, but automatically as I type or at least as I save: enter image description here

2 Answers 2

4

There is an vs code extension that does this: https://marketplace.visualstudio.com/items?itemName=usernamehw.remove-empty-lines

or you can do it manually using regular expressions:

  • Open your code in Visual Studio Code

  • From Edit Menu, select Replace or use a short cut key (command + Option + F on Mac or Ctrl + H on Windows)

  • In the find box type ^(\s)*$\n

  • Leave the replace box empty

  • Make sure the 'Use Regular Expression' is selected

  • Select the 'Replace All' button

For more info on this see this answer.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! This extension does it automatically when saving for example?
Just figured it out that it does delete them on save, I have put it in the answer
3

Adding to Dmyto answer:

That extension works great: After installing it in the settings.json from .vscode folder I added these two lines 4 and 5 (they will autocomplete once the extension is installed): add lines 4 and 5

you can then set up the values as you wish

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.