没记住的快捷键

  • Ctrl+G 跳转到相应的行

  • Ctrl+J 合并行(已选择需要合并的多行时)

  • Ctrl+L 选择整行(按住-继续选择下行)

  • Shift+鼠标右键(或使用鼠标中键)可以用鼠标进行竖向多行选择

  • Ctrl+Shift+L 鼠标选中多行(按下快捷键),即可同时编辑这些行

  • Ctrl+T 词互换

  • Ctrl+U 软撤销

  • Ctrl+Y 恢复撤销

  • Ctrl+K Backspace 从光标处删除至行首

  • Ctrl+Shift+K 删除整行

  • Ctrl+K+B 开启/关闭侧边栏

  • Ctrl+KK 从光标处删除至行尾

  • Ctrl+K+U 改为大写

  • Ctrl+K+L 改为小写

  • Ctrl+Tab 当前窗口中的标签页切换

  • Shift+F2 上一个书签

  • F2 下一个书签

  • Ctrl+F2 设置/取消书签

  • Ctrl+Shift+↑可以移动此行代码,与上行互换

  • Ctrl+Shift+↓可以移动此行代码,与下行互换

来写一个插件

  1. import sublime, sublime_plugin
  2. import datetime
  3. class FileHeaderCreatorCommand(sublime_plugin.TextCommand):
  4. def run(self, edit):
  5. # print(self.view.settings().get("author"))
  6. if self.view.size() == 0:
  7. self.check_file_type(edit)
  8. def check_file_type(self, edit):
  9. file_path = self.view.file_name()
  10. pos = file_path.rfind('.')
  11. if pos == -1:
  12. return
  13. suffix = file_path[pos+1:]
  14. token = '/'
  15. if sublime.platform() == 'windows':
  16. token = '\\'
  17. file_name_pos = file_path.rfind(token)
  18. if file_name_pos == -1:
  19. return
  20. file_name = file_path[file_name_pos+1:]
  21. header = ''
  22. if suffix == 'py':
  23. header = self._python(file_name)
  24. elif suffix == 'cpp':
  25. header = self._cpp(file_name)
  26. elif suffix == 'h':
  27. header = self._h(file_name)
  28. elif suffix == 'hs':
  29. header = self._haskell(file_name)
  30. self.view.insert(edit, 0, header)
  31. def _h(self, name):
  32. author = self.view.settings().get("author")
  33. if author is None:
  34. author = "Anonymous"
  35. company = self.view.settings().get("company")
  36. if company is None:
  37. company = "Anonymous"
  38. string = "/*\n"
  39. string += " * " + name + "\n"
  40. string += " * Created By: " + author + "\n"
  41. string += " * " + company + "\n"
  42. string += " * Created Time: " + datetime.date.today().isoformat() + "\n"
  43. string += " */\n"
  44. string += "#ifndef _" + name.replace('.', '_').upper() + "\n"
  45. string += "#define _" + name.replace('.', '_').upper() + "\n\n\n"
  46. string += "#endif"
  47. return string
  48. def _python(self, name):
  49. author = self.view.settings().get("author")
  50. if author is None:
  51. author = "Anonymous"
  52. string = "#!/usr/bin/env python3\n"
  53. string += "# coding=utf-8\n"
  54. string += "# Created Time: " + datetime.date.today().isoformat() + "\n\n"
  55. string += "__author__ = " + "\'" + author + "\'"
  56. return string
  57. def _cpp(self, name):
  58. author = self.view.settings().get("author")
  59. if author is None:
  60. author = "Anonymous"
  61. company = self.view.settings().get("company")
  62. if company is None:
  63. company = "Anonymous"
  64. string = "/*\n"
  65. string += " * " + name + "\n"
  66. string += " * Created By: " + author + "\n"
  67. string += " * " + company + "\n"
  68. string += " * Created Time: " + datetime.date.today().isoformat() + "\n"
  69. string += " */\n"
  70. return string
  71. def _haskell(self, name):
  72. pass
  73. class FileHeaderCreator(sublime_plugin.EventListener):
  74. def on_load(self, view):
  75. print("FileHeaderCreator on_load invoked")
  76. view.run_command("file_header_creator")
  77. def on_post_save(self, view):
  78. print("FileHeaderCreator on_post_save invoked")
  79. view.run_command("file_header_creator")