Sublime Forum

Leave one empty line every time I press return

#1

Hi, does anyone here know any settings which would let me leave an empty line every and jump to the next one every time I press return while writing?
So that the code would look like this:

import java.util.Scanner;

class Es05_1 {

public static void main(String[] args) {
	
	Scanner console = new Scanner(System.in);

0 Likes

#2

Do you want this to happen on every press of the return key or only in some situations?

0 Likes

#3

Every time.

0 Likes

#4

When selecting Preferences: Key Bindings in the Command Palette, you can search for enter on the left side to see the default bindings. You will see this binding:

{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"} },

Now, the easy solution would be to just copy this to the user file on the right and replace \n with \n\n, but that will end up overriding various other bindings that use the enter key but are only active in certain contexts. What we need to do now is to negate the contexts’ conditions in our custom binding, since it would otherwise take priority and always be active.

As a result, put this on the right panel in your user keymap:

  { "keys": ["enter"], "command": "insert", "args": {"characters": "\n\n"}, "context": [
    { "key": "auto_complete_visible", "operand": false },
    { "key": "panel_has_focus", "operand": false },
    { "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\{$|>$" },
  ] },
2 Likes