【问题标题】:ST2 and Emacs: Delete Whole / Entire Word + Whitespace to the rightST2 和 Emacs:删除整个/整个单词 + 右侧的空格
【发布时间】:2013-03-12 19:02:37
【问题描述】:

来自文字处理背景,我已经习惯于看到delete word 的行为如下:删除整个单词以及单词后的所有空格。我假设插件delete_word.py(在/Packages/Default 内)为有编程背景的人保留空白。

为了近似我习惯看到的行为,有必要将光标放在前一个单词的末尾,删除下一​​个单词(这样完成后两个单词之间只剩下一个空格)。

Sublime 是否已经内置了另一个键盘快捷键,可以完成我最习惯的行为?

【问题讨论】:

  • 什么是delete_word.py
  • delete_word.py 是文件夹/Packages/Default 中的python 脚本插件。它链接到"ctrl+backspace""ctrl+delete" 的OSX/Mac 键盘映射,具体取决于用户是要向前删除还是向后删除。我将编辑问题以添加单词插件。
  • 使用代码编辑器而不是文字处理器,我发现文字处理器删除的不仅仅是带有 ctrl+backspace 的单词,即使它是一个额外的句号或撇号,这很烦人。我不知道为什么它很烦人,但感觉就是这样。
  • 这正是我的想象——花费多年编码的人期望一种特定的行为;而顽固的文字处理器期望完全不同的东西。我现在正在使用 SublimeText2 处理所有事情(包括使用 LaTeX 进行文字处理),但我不确定我是否会习惯打破这些年来一直担任秘书的旧习惯。

标签: emacs editor keyboard-shortcuts sublimetext2 sublimetext


【解决方案1】:

解决方案 #1 -- Sublime Text 2:

无论出于何种原因,super+d aka ⌘+d aka find_under_expand使用宏。 find_under_expand 似乎不是插件。因此,这是一个使用宏的示例 select-entire-word 插件:

 import sublime, sublime_plugin

 class Expand(sublime_plugin.TextCommand):
     def run(self, edit):
         regions = []
         for s in self.view.sel():
             word = self.view.word(sublime.Region(s.begin(), s.end()))
             if word.end() == s.end():
             # to deal with an end of line issue
                 word = self.view.word(sublime.Region(s.end(), s.end() + 1))
             regions.append(word)
         for r in regions:
             self.view.sel().add(r)

接下来,安装dacap写的Shrink-Whitespaces插件:

https://github.com/dacap/sublime-shrink-whitespaces.

然后,创建这个宏。将空格缩小两 (2) 次处理存在制表符或制表符+空格的情况。

[
 {
      "args": null,
      "command": "expand"
 },
 {
      "args": null,
      "command": "right_delete"
 },
 {
      "args": null,
      "command": "shrink_whitespaces"
 },
 {
      "args": null,
      "command": "shrink_whitespaces"
 },
 {
      "args":
      {
           "characters": " "
      },
      "command": "insert"
 }
]

解决方案 #2 -- Sublime Text 2:

安装:https://github.com/bits/ExpandSelectionToWhitespace-SublimeText

创建一个宏并将其绑定到您最喜欢的键盘快捷键:

[
    {
        "args": null,
        "command": "expand_selection_to_whitespace"
    },
    {
        "args":
        {
            "by": "wordends",
            "extend": true,
            "forward": true
        },
        "command": "move"
    },
    {
        "args":
        {
            "by": "words",
            "extend": true,
            "forward": false
        },
        "command": "move"
    },
    {
        "args": null,
        "command": "left_delete"
    }
]

解决方案#1——Emacs——定义两个函数,并创建一个宏:

(fset 'lawlist-kill-word [?\C-= kp-delete ?\C-+])

(global-set-key (kbd "C-=") 'lawlist-mark-word)

(global-set-key (kbd "C-+") 'delete-horizontal-space-forward)

(defun lawlist-mark-word ()
  "Mark the entire symbol around or in front of point."
  (interactive)
  (let ((symbol-regexp "\\s_\\|\\sw"))
    (when (or (looking-at symbol-regexp)
              (looking-back symbol-regexp))
      (skip-syntax-forward "_w")
      (set-mark (point))
      (while (looking-back symbol-regexp)
        (backward-char)))))

(defun delete-horizontal-space-forward () ; adapted from `delete-horizontal-space'
      "*Delete all spaces and tabs after point."
      (interactive "*")
      (delete-region (point) (progn (skip-chars-forward " \t") (point))))

【讨论】:

  • delete-horizo​​ntal-space-forward() 谢谢,这正是我需要的,不知道为什么默认没有delete-horizo​​ntal-space等价物。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多