Sublime Forum

Map a command to insert a ";" at the end of line

#1

I’d like to map a command to insert a ; at the end of a line. Example:

var fo|o:String = "bar"

The | depicts the current cursor position. Then I press a key like ctrl+; and it puts a ; at the end, like:

var foo:String = "bar";

How can I do that?

0 Likes

#2
self.view.insert(edit, self.view.line(self.view.sel()[0].begin()).end(), ";")
0 Likes

#3

How can I bind a key to that?

0 Likes

#4
  1. Tools - New Plugin
  2. Add that line indented under def run
  3. Change “class ExampleCommand” to “class AddSemicolonEndoflineCommand”
  4. Save as add_semicolon_endofline.py to your Users directory
  5. Add to your key bindings:
    { “keys”: “f5”], “command”: “add_semicolon_endofline” },
0 Likes

#5

Thank you.

0 Likes