Sublime Forum

Toggle Comment and move to the next/previous line

#1

I’m trying to achieve such behaviour but without success. Does ST has a command to move to a next/previous line?

0 Likes

#2

I often create a script with Autohotkey to work around software limitations. If you are interested in learning, it is worthwhile, as you can complement or create new hotkeys regardless of the software manufacturer.

0 Likes

#3

If you have the Chain of Command installed, you can write a simple key binding for it :-

{
	"keys": ["ctrl+alt+shift+n"],
	"command": "chain",
	"args": {
		"commands": [
			["toggle_comment"],
			["move", {
				"by": "lines",
				"forward": true
			}]
		]
	}
},

forward -> true will advance the cursor to the next line & false will advance it to the previous line.

0 Likes

#4

I’m going to create an apple script or something if the situation needs it :wink:

Oh maybe this would be a good opportunity to learn JXA.

0 Likes

#5

You can also do this in core Sublime with no plugins by creating a macro that executes the toggle command and then moves down a line:

3 Likes

#6

Nice one. I rarely use macros but this approach is nicer (plus no need for any plugin).

0 Likes

#7

This is exactly what I needed. Thanks!

0 Likes