求一个类似vscode的缩进功能,向前缩进4个空格或者回退四个空格

类似vscode的

C-[ (该行向前缩进一个tab(4个空格))

C-] (该行回退缩进一个tab(4个空格))

搞了好久的emacs的缩进都不尽人意啊。

问题解决了,用下面这个控件,我在list-package里面找的。

然后再minor-mode里面配置,搞定。

自此我的emacs基本就覆盖了vscode所有编辑快捷键功能。

3 个赞

我之前也有这个问题!后来因为用EVIL所以直接选中后通过 <> 做缩进了。 :joy: 回头试一试这个包。

我刚好也写了一个,一直在用,加 C-u 表示回退:

(defun my/indent-4-space (backward)
  "Indent/dedent region or insert/delete 4 sapce."
  (interactive "P")
  (cond ((and (use-region-p) backward)
         (replace-regexp "^    " "" nil (region-beginning) (region-end)))
        ((and (use-region-p) (not backward))
         (replace-regexp "^" "    " nil (region-beginning) (region-end)))
        (backward
         (let ((spaces 4)
               char)
           (while (> spaces 0)
             (setq char (char-after (point)))
             (cond ((char-equal (char-after (point)) 32) ; delete a space char
                    (delete-char 1)
                    (setq spaces (- spaces 1)))
                   ((char-equal (char-after (point)) 9) ; delete a tab char
                    (delete-char 1)
                    (setq spaces (- spaces 4)))))))
        (t (insert "    "))))
1 个赞