make ctrl+enter add semicolon to the end of the line

白昼怎懂夜的黑 提交于 2019-12-11 03:21:59

问题


Ctrl+enter in sublimetext is a default shortcut to create a new line, no matter in what position your cursor are in the current line. However, sometimes I need to add a semicolon at the end of the current line before jump to a new line.

How can i make the "ctrl+enter" shortcut add a semicolon to the end of the current line before create a new line? Is it even possible?

sorry for my english.


回答1:


You can simply modify the macro /Default/Add Line.sublime-macro to insert the semicolon.

From this

[
    {"command": "move_to", "args": {"to": "hardeol"}},
    {"command": "insert", "args": {"characters": "\n"}}
]

to this

[
    {"command": "move_to", "args": {"to": "hardeol"}},
    {"command": "insert", "args": {"characters": ";\n"}}
]



回答2:


After AGS's answer, I solved my problem with similar approach. You can do this:

1. Create a macro file in the folder ~/.config/sublime-text-3/Packages/User with:

[ { "args": { "to": "hardeol" }, "command": "move_to" }, { "args": { "characters": ";" }, "command": "insert" }, { "args": { "characters": "\n" }, "command": "insert" } ]

2. Then edit your keybindings Preferences > Key Bindings - User. Add this:

{ "keys": ["ctrl+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/User/FILENAME.sublime-macro"} },


来源:https://stackoverflow.com/questions/27715141/make-ctrlenter-add-semicolon-to-the-end-of-the-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!