How to remove indentation on newline

Does anyone know how to remove indentation on newline event?

My current config is:

{ lineNumbers: true, mode: "javascript", smartIndent: false, tabSize: 2 }

When i enter

function() {
  alert("test");

then press enter, the newly added line will keep the indentation of two spaces.
However i want every line to start with zero indentation when i press enter.

How to achieve this?

Thanks in advance
Benjamin

1 Like

Bind Enter to a command like cm => cm.replaceSelection("\n") rather than the default, the newlineAndIndent command.

2 Likes

perfect, thx!

But in my case, cursor jump through one empty line. How fix this? Thanks in advance
In Angular 5 + Electron
html:

   <codemirror
     [config]="{
       lineWrapping: true, 
       autofocus: true, 
       showCursorWhenSelecting: true,
       smartIndent: false
     }"
     (keyup.enter)="removeIndentation()"
     #novelEditor>
   </codemirror>

ts:

import { CodemirrorComponent } from 'ng2-codemirror';
...
@ViewChild('novelEditor') private novelEditor: CodemirrorComponent;
...
  removeIndentation() {
    const cm = this.novelEditor.instance;
    cm.replaceSelection("\n");
  }

Screenshot_11

I solved it

removeIndentation() {
   const cm = this.novelEditor.instance;
   cm.execCommand('delLineLeft');
}