Sublime Forum

Non-smart auto indent?

#1

I’m new to sublime text, so sorry if this has been answered before! Is there an indentation mode that maintains the current indentation but doesn’t automatically change indentation when braces are entered? I’ve tried googling for an answer or a plugin to accomplish this but have had no luck. Any help is appreciated!

0 Likes

#2

You could try:

    "auto_indent": true,
    "smart_indent": true,

In your user preferences. Not sure it’ll get you exactly what you want, but you’ll likely be closer.

:smile:

0 Likes

#3

I am also new to sublime. Use Notepad++ in Windows and trying alternatives for Linux.
The same problem annoys me.
Many editors have:

  • No indent mode.
  • Block indent mode - Enter moves cursor to the exact indent of previous line. This mode does not assume any knowledge about the edited language.
  • Smart indent mode - Whatever the developer thinks is “smart”.

Sublime is missing the “block mode”.

0 Likes

#4

One more note that was hinted before but should be made explicit. This indentation after open brace is language specific.
If I press enter while syntax highlighting is ‘c’ it will indent.
For regular text file it will not indent.
I think that the user should be able to disable ‘language’ indentation if he wants to.

0 Likes

#5

You will want to look into package overrides and overriding the file Packages/C++/Indentation Rules.tmPreferences.

0 Likes

#6

Thanks for the tip. I took me additional 2 hours of research but here is the newbie guide to enable “block mode” tabs for C/C++ (in Linux):

Install package control from:
https://packagecontrol.io/

Make a local copy of C++ indentation in your home directory.
You need to unzip the file: Indentation Rules.tmPreferences
From the zip file: /opt/sublime_text/Packages/C++.sublime-package
To your local directory: ~/.config/sublime-text-3/Packages/C++
Here is how to do it with a single long command:
unzip /opt/sublime_text/Packages/C++.sublime-package Indentation\ Rules.tmPreferences -d ~/.config/sublime-text-3/Packages/C++

Open the file you just extracted with a text editor (E.g. sublime):
~/.config/sublime-text-3/Packages/C++/Indentation Rules.tmPreferences

For each of the keys:
decreaseIndentPattern
increaseIndentPattern
bracketIndentNextLinePattern
unIndentedLinePattern
Delete everything between <string> and </string>

It should look like this:
<key>decreaseIndentPattern</key> <string></string> <key>increaseIndentPattern</key> <string></string> <key>bracketIndentNextLinePattern</key> <string></string> <key>unIndentedLinePattern</key> <string></string>

In order for sublime to use new setting use the following procedure:
Preferences -> Package Control -> Disable Package -> C++
Restart sublime text
Preferences -> Package Control -> Enable Package -> C++

Perhaps there is simpler way but this is what I found.

0 Likes