At work we have the convention on using 4 spaces for code indentation. I'm accustomed to using tabs
for indentation, but want to follow the convention.
Note: it is not my intention to start a discussion on spaces vs tabs here.
I adjusted my Visual Studio settings to replaces tabs with 4 spaces, but I have some issues adjusting to using spaces.
For example:
How can I easily un-indent code? with tab
chararaters, I only
needed to use backspace one time, with spaces I need to use backspace
4 times.
How can I make sure that there is always the correct amount of spaces (not three or five)?
How can I navigate through my code as fast as I could with tabs? (arrow left or right jumps to the next indentation with tabs, but moves only a single position with spaces)
How can I ignore whitespace changes when comparing files?
Idealy, I would like these 4-spaces for indentation to work equally to tab characters.
I work mainly with c# and XML-based files.
Any tips are welcome!
Sets the distance in spaces between tab stops. The default is four spaces.
Conclusion. So, at the end of the day, tabs versus spaces is truly a matter of preference, however the tab is still the character specifically designed for indentation, and using one tab character per indentation level instead of 2 or 4 spaces will use less disk space / memory / compiler resources and the like.
Such a shame that Visual Studio does not implement smart unindent. You can find this feature it even in the most simple free notepad-like editors.
Fortunately, to simplify auto-unindent with Backspace and Delete, there is an awesome plugin, TabSanity by jedmao (Jed Hunsaker).
This package causes the Visual Studio text editor to treat tabs-as-spaces as if they were actually tabs. That is, the backspace and delete keys, arrow key navigation and mouse cursor text selection (coming soon) will not allow the caret to land within the spaces that form a tab.
Note that it requires as dependency another cool plugin, EditorConfig .
Both are highly recommended for "tabs-as-spaces" text maniacs.
Happy coding!
To un-indent, highlight the line and hit Shift+Tab. Or just position to the beginning of the line and hit Shift+Tab.
Also, hitting Tab will enter the correct number of spaces to align at the next 4-space boundary.
To make sure indentation is correct, you can highlight an area of code and select Edit -> Advanced -> Format Selection, or you can just go to the end of a block, remove the ending brace, and add it back. The IDE will reformat your code.
So, if you have this:
void foo()
{
f();
int q = 32;
for (; q > 0; --q)
{
// really messed up indentation
}
}
Then deleting and re-adding that final '}'
will reformat the entire method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With