Duplicate line and comment out old one

我与影子孤独终老i 提交于 2019-12-25 03:17:12

问题


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

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