Sublime Forum

[Solved] Customize: One-line if statement indentation

#1

When I have only one command for if to execute, I often write it on the same line as the condition and without any { } brackets.

The problem is, Sublime Text indents the next line, as if I’m now writing the block of commands for the if. It’s not a deal-breaker for this wonderful software, but it’s sometimes can become very annoying to delete these indents manually. Any chance that it might be fixed in the near future?

The video showing the bug: http://www.youtube.com/watch?v=VJdQxaIHLbk

Thanks in advance!

0 Likes

#2

The unexpected indentation only occurs with for as shown in the video, not with if. Anyway, here is a way to correct it on your own:

From the Sublime Text 2 menu, select ‘[Sublime Text 2 →] Preferences → Browse Packages…’. Then open for editing ‘C++/Indentaion Rules.tmPreferences’. Find:^ \s* \b(if|while|else)\b ^;]* $ | ^ \s* \b(for)\b .* $Replace with:^ \s* \b(if|while|else|for)\b ^;]* $
For an even better experience, replace with this instead:^ \s* \b(if|while|else|for)\b ^{;]* $This will prevent the unexpected indentation from occurring after single-line conditions and loops with empty block bodies (e. g. ‘for (;:wink: {}’) in addition to those with single- or multi-statement bodies.

1 Like

#3

How do you do this with sublime text 3?

When I go to Preferences/Browse Packages/User there is nothing there

0 Likes

#4

The recommended way to modify files that are part of the default packages is to install PackageResourceViewer through Package Control.

Then you can get to the C++ files by:

  • opening the Command Palette
  • type PRV and select PackageResourceViewer - Open Resource
  • select C++
3 Likes

#5

bruh… thanks man… I was frustrated with my settings.

0 Likes