Sublime Forum

How can I keybind repl_python_run?

#1

I’m trying to bind a key to “repl_python_run”, so I don’t have to navigate the context menus every time I want to run some python code inside Sublime. I’ve found a few related posts, but some are for version 2 and others I can’t seem to get to work.

so far my code is:

{ "keys": ["super+shift+r"], "command": "run_existing_window_command", "args":
        {
          "id": "repl_python_run",
           "file": "config/Python/Main.sublime-menu" }
        }

This seems like it tries to do something, because I can see it running in the status bar at the bottom, but the REPL window never pops up or anything.

0 Likes

#2

I’m still looking for a solution, anyone know how I might fix this?

0 Likes

#3

I’m not familiar with the id key.   Maybe that is from an older version of SublimeText.

You should be able to use repl_python_run as the value for the command key, and eliminate the line of the id key.

 

If you need more info, check out this post by @Kicweed on setting up plugins, keybindings, and commands.

0 Likes

#4

Ok, I managed to get it to save without any errors, however there must be something wrong somewhere because when I restarted sublime and pressed the key shortcut super + shift + r it did nothing at all. Any ideas?

[
    { "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
         [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         //{ "key": "auto_complete_visible", "operator": "not_equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(\\]|\\)|\\}|>|\\\"|'|\\;)", "match_all": true },
         { "key": "has_next_field", "operator": "not_equal", "operand": true },
           ]
        },

    { "keys": ["super+shift+r"], "command": "repl_python_run", "file": "config/Python/Main.sublime-menu", "context":
        []
        } 

       ]
0 Likes

#5

 
Use this as a point of reference:

	{
		"keys": [ "ctrl+alt+space" ],
		"command": "your_command_name",
		"args":
			{
				"arg_1": "string1",
				"arg_2": 123,
				"arg_3": false,
			},
		"context":
			[
				{ "key": "context_1", "operator": "value1", "operand": true },
				{ "key": "context_2", "operator": "value2", "operand": false },
			],
	},

 



 
Note the comma placement after each value and sets of bracketed content.

Technically, you don’t need commas at the last entry of each nested level.   I tend to be lazy about this and just include them regardless of whether something is the last entry or not, because it’s less work to maintain & won’t cause any issues.

 
If you still need further assistance, study your Default.sublime-keymap file & look into JSON guidelines.

0 Likes

[Solved] Problem about ST2 with windows10
#6

I got it to work, in case anyone else wants to use my exact keybinds (or you can omit the top half, if not) It works with no problems in Sublime Text 3

[
    { "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
         [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         //{ "key": "auto_complete_visible", "operator": "not_equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(\\]|\\)|\\}|>|\\\"|'|\\;)", "match_all": true },
         { "key": "has_next_field", "operator": "not_equal", "operand": true },
           ]
        },

{ "keys": ["ctrl+shift+."], "command": "run_existing_window_command", "args":
        {
        "id": "repl_python_run",
        "file": "config/Python/Main.sublime-menu"
        }
}       
       ]
2 Likes