Keep Indentation option for delete-to-beginning-of-line


#1

Hi all,

I haven’t seen any articles that discuss this yet. In some text editors (I’m thinking of Xcode) when you hit cmd-delete, it deletes the line text but keeps the indentation. Any chance we could add a key binding for this behavior?


#2

This is a decent project for init.coffee. You would start by grabbing editor.getCursors(). Now, each Cursor is also a zero-length Selection, so we can use the selection API. For each cursor, run cursor.selection.selectLine(), take selection.getText() and run text.replace(/(\s*)\b.*/i, "$1") (this will filter out everything except leading whitespace). Finally, use selection.insertText() to put the whitespace back where the line was.