我已将上下文菜单的键绑定编码为:
command
:context_menu
查看拼写建议但是对下一个单词的方式进行操作并将光标放在单词的末尾则不起作用。但是如果光标在单词内或单词的开头,它确实有效。有没有一种简单的方法可以说回去一个角色然后调出上下文菜单?
也可以在上下文菜单中使ctrl+n
和ctrl+p
工作。假设上下文菜单已关闭默认绑定。
结束使用下面答案的建议,但只是略有不同的解决方案,让你回到命令运行后的单词的开头我做了这个:
{
"keys": ["ctrl+alt+w"],
// Force ability to bring up context menu
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
"args": {
"commands": [
// ["move", {"by":"word", "forward": false, "extend": false}],
["sbp_move_word", {"direction": -1}],
["context_menu"],
["move", {"by":"wordends", "forward": true, "extend": false}],
] }
},
// Do not use "find_under_expand" if selection is made
{
"keys": ["ctrl+alt+w"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": false } ],
"args": { "commands": [
["sbp_move_word", {"direction": -1}],
// ["move", {"by":"word", "forward": false, "extend": false}],
["context_menu"],
["move", {"by":"wordends", "forward": true, "extend": true}],
] }
},
出于某种原因,我在使用常规移动命令时遇到了问题,但是也应该工作正常,所以在sublemacs上面注释掉它:
答案 0 :(得分:1)
将此添加到您的键绑定:
// Use "find_under_expand" if no selection is made
{
"keys": ["ctrl+super+alt+t"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true } ],
"args": {
"commands": [
["find_under_expand"],
["select_word_beginning"],
["context_menu"],
] }
},
// Do not use "find_under_expand" if selection is made
{
"keys": ["ctrl+super+alt+t"],
"command": "chain",
"context": [ { "key": "selection_empty", "operator": "not_equal", "operand": true } ],
"args": {
"commands": [
["select_word_beginning"],
["context_menu"],
] }
},
find_under_expand
命令将选择插入符号中的单词,这使context_menu
能够始终使用拼写建议执行。
第二个键绑定不使用find_under_expand
,因为这会导致您选择的文本的多个实例被选中。
将SelectWordBeginnings.py
保存在/Packages/
目录中的某个位置:
import sublime, sublime_plugin
class SelectWordBeginningCommand ( sublime_plugin.TextCommand ):
def run ( self, edit ):
view = self.view
selections = view.sel()
if len ( selections ) == 0:
return
selection = selections[0]
if selection.a < selection.b:
newSelection = sublime.Region ( selection.b, selection.a )
view.selection.clear()
view.selection.add ( newSelection )
此命令将反转所选区域,因此插入符始终位于单词的开头。