Matthew Note

Sublime Text & Plugin

没记住的快捷键

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