问题
I often need to edit a line but comment out the old one.
Is it possible to create a key binding for these commands in Sublime Text 2?
- duplicate current line
- comment out the top line
- move the cursor to the bottom line
回答1:
Assuming the comment syntax is defined for the file type, you can use a simple macro (though even if it's not you could do it, the macro would just be a little more involved). Anyways, save the following in Packages/User
as whatever you like. Be sure the extension is .sublime-macro
though.
[
{
"args":
{
"block": false
},
"command": "toggle_comment"
},
{
"command": "duplicate_line"
},
{
"args":
{
"block": false
},
"command": "toggle_comment"
}
]
Then, create a key binding like the following.
{ "keys": ["f12"], "command": "run_macro_file", "args": {"file": "res://Packages/User/<the file name>.sublime-macro"} },
Of course, change the keys
and <the file name>
as appropriate.
来源:https://stackoverflow.com/questions/19716708/duplicate-line-and-comment-out-old-one