热键以分号结尾并跳至Sublime Text 2中的新行 [英] Hotkey to end the line with a semicolon and jump to a new line in Sublime Text 2

查看:112
本文介绍了热键以分号结尾并跳至Sublime Text 2中的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出工作中的热键.我刚得到这份工作,这是我一生中第一次或多或少使用Mac.

I'm trying to figure out a hotkey at work. I just got this job and I am using a Mac for more or less the first time in my life.

回到我的笔记本电脑上,使用Eclipse时,我似乎还记得有一个热键可以同时使用:

Back home on my Laptop, when using Eclipse, I seem to remember there being a single hotkey which would both:

  • 在当前行的结束中添加;(无论插入符号在所述行中的何处)
  • 将光标放在新行的开头,其缩进级别与我刚刚在其中添加分号的行的缩进级别
  • Add a ; to the end of my current line (no matter where the caret was within said line)
  • Place my cursor at the beginning of a new line, with the same indentation level as the line I had just added a semicolon to

有人知道这是否是Eclipse特定的热键,还是知道在Sublime Text 2中复制该热键的方法?

Does anybody know if this was an Eclipse-specific hotkey, or know of a way to replicate said hotkey in Sublime Text 2?

推荐答案

为此的最佳解决方案是在Sublime Text上录制宏,然后将其分配给键盘快捷键.请按照下列步骤操作:

Best solution for this is recording a macro on Sublime Text and then assigning it to a keyboard shortcut. Follow these steps:

  1. 创建诸如alert('hello')之类的行并将光标保持在右侧 在字母"o"之后.
  2. 然后转到工具>录制宏开始录制.
  3. Command + 转到行尾.
  4. ; 并按 Enter
  5. 转到工具>停止录制宏
  6. ,停止录制宏
  7. 您现在可以通过工具>播放宏(可选)
  8. 来测试宏
  9. 通过转到工具>保存宏(例如:EndOfLine.sublime-macro)来保存宏
  10. 通过在您的方括号之间添加快捷方式来创建快捷方式 在偏好设置">按键绑定-用户文件"中

  1. Create a line such as alert('hello') and leave the cursor right after letter 'o'.
  2. Then go to Tools > Record a Macro to start recording.
  3. Press Command+ to go to the end of line.
  4. Press ; and hit Enter
  5. Stop recording the macro by going to Tools > Stop Recording Macro
  6. You can now test your macro by Tools > Playback Macro (optional)
  7. Save your macro by going to Tools > Save Macro (ex: EndOfLine.sublime-macro)
  8. Create a shortcut by adding this between the square brackets in your in your Preferences > Key Bindings - User file:

{
"keys": ["super+;"], "command": "run_macro_file", "args": {"file": "Packages/User/EndOfLine.sublime-macro"}
}

  • 现在,每次您按 Command + ; 时,它将 将分号神奇地放在当前行的末尾,然后将光标移到下一行.
  • Now, every time you hit Command+;, it will magically place the semicolon at the end of current line and move the cursor to the next line.
  • 祝您编程愉快!

    这篇关于热键以分号结尾并跳至Sublime Text 2中的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆