Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sublime text new line loses indent

I have a problem that is causing me lots of extra keystrokes in sublime text. When I create a couple of new lines, the indentation is correct. However, if I up arrow back to those new lines, the indentation is gone and I am back at position 0 (happens for all file formats). Am I doing it wrong, is this intended behaviour? I like white space in my code so this is a pain.

Recreating: Write function code e.g.

    function Bob(){
        | indent starts here
    }

All good. I then add a couple of new lines, up arrow back to the middle and I get this:

    function Bob(){
| indent starts here
| indent starts here
        | indent starts here
    }

I would like:

    function Bob(){
        | indent starts here
        | indent starts here
        | indent starts here
    }

Any suggestions please - apart from changing my coding style :-) Thanks.

Edit: apparently this is not expected behaviour. Preferences and plugins listed below in case they are interfering.

User preferences:

{
"auto_complete": true,
"auto_complete_with_fields": true,
"bold_folder_labels": true,
"caret_style": "phase",
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"detect_indentation": true,
"draw_minimap_border": true,
"fade_fold_buttons": true,
"folder_exclude_patterns":
[
    ".svn",
    ".git",
    ".hg",
    "CVS",
    "tmp",
    ".tmp",
    ".bundle",
    ".sass-cache"
],
"highlight_modified_tabs": true,
"ignored_packages":
[
    "Vintage"
],
"line_padding_bottom": 1,
"line_padding_top": 1,
"soda_classic_tabs": true,
"tab_size": 4,
"theme": "Soda Light.sublime-theme",
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true,
"wrap_width": 200
}

Plugins:

  • Emmet
  • GitGutter
  • Package Control
  • PyV8
  • Sass
  • SFTP
  • Sidebar enhancements
  • Theme - soda
like image 651
Websemantic Avatar asked Nov 27 '13 15:11

Websemantic


People also ask

How do I fix sublime indentations?

Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces.

How do I indent a line in Sublime Text?

Select all code that you intend to indent, then hit Ctrl + ] in Sublime text to indent. For macOS users, use command + ] to indent, and command + [ to un-indent.

How do I indent multiple lines in Sublime Text?

You can use ctrl+ ] to indent a line (or highlighted block), and ctrl + [ to unindent.

How do I change the tab space in Sublime Text?

To configure the tab width in Sublime Text 3, click on “View” in the top bar, then click on “Indentation” in the drop-down list. Next, in the second level of the drop-down list select the width you want a tab to take up. Sublime Text 3 defaults to tabs being four spaces wide.


1 Answers

Add the following to your preferences and you should be all set:

"trim_automatic_white_space": false,

The default is true, and when set it trims white space added by auto_indent when moving the caret off the line.

like image 81
MattDMo Avatar answered Oct 11 '22 22:10

MattDMo