【问题标题】:sublime text 3: key-bound commands for jumping to next and previous spacesublime text 3:用于跳转到下一个和上一个空格的键绑定命令
【发布时间】:2016-09-28 17:58:07
【问题描述】:

在 vim 中,f<space>F<space> 分别将光标向前移动到下一个空格和向后移动到上一个空格。

Sublime Text 3 中是否有相同的命令?如果是这样,请演示它在键绑定中的用途。

【问题讨论】:

  • Sublime text 有复古模式,支持 f/F 就像 vim 一样,不是吗?
  • @Jimmyliu 感谢您指出 Vintage,但我不想进入必须在模式之间切换的 vim 样式编辑。我使用 Sublime 是有原因的。 :-)
  • 我明白了,好点

标签: sublimetext3


【解决方案1】:

Ctrl + Left & Ctrl + Right 按单词边界移动插入符号,包括空格。

您可以通过编辑word_separators 值来更改在User Settings 中指示单词边界的字符。


Sublime Text 也有 Vintage Mode,它模拟了许多 VIM 的功能,包括:
l, h, j, k, W, w, e, E, b, B, alt+w, alt+W, $, ^, %, 0, G, gg, f, F, t, T, ^f, ^b, H, M, L

【讨论】:

  • 正如您所指出的,ctrl+left/right 并没有完全像 f/F<space> 那样做。是否可以为一个键绑定指定word_separators?如果是这样,根据我的问题,你能演示一下如何做到这一点吗?
  • @kkurian: 你不能,word_separators 只能设置在 [ 全局 |语法 |项目 |查看]上下文。你试过复古模式吗?我不是 Vim 用户,但它说它具有 fF 功能。以及:l, h, j, k, W, w, e, E, b, B, alt+w, alt+W, $, ^, %, 0, G, gg, f, F, t, T, ^f, ^b, H, M, and L
  • 感谢您指出 Vintage,但我不想进入必须在模式之间切换的 vim 样式编辑。我使用 Sublime 是有原因的。 :-)
【解决方案2】:

将以下代码保存到:
/Packages/MoveToSpace/MoveToSpace.py

import sublime, sublime_plugin

class MoveToSpaceCommand( sublime_plugin.TextCommand ):
    def run( self, edit, mode ):

        view = self.view
        selections = self.view.sel()

        if len( selections ) == 0:
            return

        newSelections = []

        for selection in selections:

            spacePoint = None

            if mode.lower() == "forward":

                spacePoint = self.view.find( "[^ ] " , selection.end() ).a

                if spacePoint != -1:
                    newSelections.append( sublime.Region( spacePoint + 1, spacePoint + 1 ) )

            elif mode.lower() == "backward":

                spaceRegions = self.view.find_all( " [^ ]")
                spaceRegion_Count = len( spaceRegions )

                for index in range( 0, spaceRegion_Count ):
                    if spaceRegions[ index ].b < selection.begin():
                        spacePoint = spaceRegions[ index ].a
                    elif spaceRegions[ index ].b >= selection.begin() \
                    and  spacePoint != None:
                        newSelections.append( sublime.Region( spacePoint + 1, spacePoint + 1 ) )
                        break

        if len( newSelections ) > 0:
            view.sel().clear()
            view.sel().add_all( newSelections )

将以下代码保存到:
/Packages/MoveToSpace/Default.sublime-keymap

[

    {
        "keys":    [ "ctrl+shift+=" ],
        "command": "move_to_space",
        "args":    { "mode": "forward" },
    },

    {
        "keys":    [ "ctrl+shift+-" ],
        "command": "move_to_space",
        "args":    { "mode": "backward" },
    },

]

包含的键绑定是:

  • Ctrl + Shift + Plus 移动到下一个空格
  • Ctrl + Shift + Minus 移动到上一个空格

您可以根据自己的喜好更改键绑定。

【讨论】:

  • ST2?它根本不起作用,例如File "./MoveToSpace.py", line 20, in run AttributeError: 'NoneType' object has no attribute 'a'。再举一个例子:File "./MoveToSpace.py", line 38, in run view.sel().add_all(newSelections) Boost.Python.ArgumentError: Python argument types in RegionSet.add_all(RegionSet, list) did not match C++ signature: add_all(SelectionSet {lvalue}, SelectionSet)
  • 另请注意:ST2 在结束大括号/方括号之前拒绝尾随逗号。在上面的Default.sublime-keymap 中有三个。 3
  • 我在 ST3 上编写 + 测试。 Idk API 差异,但您可以很容易地调整代码。有什么理由你还在 ST2 上?现在是pretty much deprecated...
  • 您的解决方案适用于我,因为我在 ST3 上。更新问题以引用 ST3 而不是 ST2。
  • 这太棒了!谢谢!给用户的一点提示:它不认为换行符是空格
猜你喜欢
  • 1970-01-01
  • 2016-01-05
  • 2013-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-05
  • 1970-01-01
  • 2016-04-13
相关资源
最近更新 更多