命令

命令是用于操作编辑器的动作,他们没有参数,主要用在上一章提到的键位映射中。你可以自己定义一些命令,方法是给CodeMirror.commands对象添加属性,属性值必须为以编辑器实例为唯一参数的函数。标准库中已经定义了一些常用的命令,他们大部分都有默认的绑定键位。

下文中末尾的几个命令虽然存在于默认的键位映射表中,但核心库并没有实现他们。因为它们的设计意图就是在插件中实现或由开发者自己实现。

如果你想在代码中运行命令,可以使用execCommand方法调用。

selectAll Ctrl-A (PC), Cmd-A (Mac)

全选编辑器中的内容。

singleSection Esc

如果同时有多个选区,则取消掉其他只剩下主选区。

killLine Ctrl-K (Mac)

Emacs风格。删掉这一行在光标后的内容,如果光标后只有空格,则连末尾的换行符也会被删掉。

deleteLine Ctrl-D (PC), Cmd-D (Mac)

删掉光标所在行,包括末尾的换行符。

delLineLeft

删掉这一行在光标前的内容。

delWrappedLineLeft Cmd-Backspace (Mac)

Delete the part of the line from the left side of the visual line the cursor is on to the cursor.

delWrappedLineRight Cmd-Delete (Mac)

Delete the part of the line from the cursor to the right side of the visual line the cursor is on.

undo Ctrl-Z (PC), Cmd-Z (Mac)

撤销。

redo Ctrl-Y (PC), Shift-Cmd-Z (Mac), Cmd-Y (Mac)

重做。

undoSelection Ctrl-U (PC), Cmd-U (Mac)

撤销选区内的上次变化。如果上次变化不是只发生在选区中,则不管那么多了,撤销上次变化。

redoSelection Alt-U (PC), Shift-Cmd-U (Mac)

参考上一条。

goDocStart Ctrl-Home (PC), Cmd-Up (Mac), Cmd-Home (Mac)

将光标移动到文档开头。

goDocEnd Ctrl-End (PC), Cmd-End (Mac), Cmd-Down (Mac)

将光标移动到文档结尾。

goLineStart Alt-Left (PC), Ctrl-A (Mac)

将光标移动本行的开头。

goLineStartSmart Home

Move to the start of the text on the line, or if we are already there, to the actual start of the line (including whitespace).

golineEnd Alt-Right (PC), Ctrl-E (Mac)

将光标移动到本行的结尾。

goLineRight Cmd-Right (Mac)

将光标移动到视觉上光标所在行的右侧,也就是说,如果内容太长折行了的话,光标可能不会出现在该行的末尾。

goLineLeft Cmd-Left (Mac)

参考上一条。

goLineLeftSmart

Move the cursor to the left side of the visual line it is on. If that takes it to the start of the line, behave like goLineStartSmart.

goLineUp Up, Ctrl-P (Mac)

将光标上移一行。

goLineDown Down, Ctrl-N (Mac)

将光标下移一行。

goPageUp PageUp, Shift-Ctrl-V (Mac)

将光标上移一个屏幕的距离,并同时滚动编辑器。

goPageDown PageDown, Ctrl-V (Mac)

参考上一条。

goCharLeft Left, Ctrl-B (Mac)

光标左移一个字符,如果已到该行的最前面,则移动到上一行。

goCharRight Right, Ctrl-F (Mac) 参考上一条。

goColumnLeft 光标左移一个字符,但即使左移到头了也不跑到上一行。

goColumnRight 参考上一条。

goWordLeft Alt-B (Mac) 将光标移动到上个单词的开头。

goWordRight Alt-F (Mac) 将光标移动到吓个单词的结尾。

goGroupLeft Ctrl-Left (PC), Alt-Left (Mac) 光标左移一组。一组是指一连串的字母、标点符号、空格。

goGroupRight Ctrl-Right (PC), Alt-Right (Mac) 参考上一条。

delCharBefore Shift-Backspace, Ctrl-H (Mac)

删除光标前的那个字符。

delCharAfter Delete, Ctrl-D (Mac)

删除光标后的那个字符。

delWordBefore Alt-Backspace (Mac)

Delete up to the start of the word before the cursor.

delWordAfter Alt-D (Mac)

Delete up to the end of the word after the cursor.

delGroupBefore Ctrl-Backspace (PC), Alt-Backspace (Mac)

Delete to the left of the group before the cursor.

delGroupAfter Ctrl-Delete (PC), Ctrl-Alt-Backspace (Mac), Alt-Delete (Mac)

Delete to the start of the group after the cursor.

indentAuto Shift-Tab

自动缩进当前行或选区。

indentMore Ctrl-] (PC), Cmd-] (Mac)

对当前行或选区增加缩进。

indentLess Ctrl-[ (PC), Cmd-[ (Mac)

对当前行或选区减少缩进。

insertTab

在光标处插入一个tab字符。

insertSoftTab

在光标处插入和tab字符等长的数个空格。

defaultTab Tab

如果当前选中了一些内容,则将它缩进一个单位;如果什么都没有选中,则插入一个tab字符。

transposeChars Ctrl-T (Mac)

将光标前后的俩字符调换位置。

newlineAndIndent Enter

插入新的一行并自动缩进好。

toggleOverwrite Insert 切换“插入”或是“替换”2种输入模式。

save Ctrl-S (PC), Cmd-S (Mac)

虽然存在于默认的键位映射表中,但核心库并没有实现这个命令。设计意图是让开发者自己实现。

find Ctrl-F (PC), Cmd-F (Mac)

findNext Ctrl-G (PC), Cmd-G (Mac)

findPrev Shift-Ctrl-G (PC), Shift-Cmd-G (Mac)

replace Shift-Ctrl-F (PC), Cmd-Alt-F (Mac)

replaceAll Shift-Ctrl-R (PC), Shift-Cmd-Alt-F (Mac)

核心库没有实现这几个命令,而是在search插件中实现的,当然开发者也可以自己实现。

results matching ""

    No results matching ""