我想缩进和整个区域n向右或向左的空格.我可以在Cc>和Cc <的某些模式下执行此操作,但我想一般这样做.
如果我需要更改我的.emacs以使其高效(使用上面的键盘快捷键)那很好.
arm*_*ino 31
对我有用的是:选择区域然后 C-u <number of spaces> C-x TAB
更新
@Eric我们可以定义一个函数并绑定到键盘快捷方式,例如C-x C-TAB.尝试将此添加到您的emacs配置中.
(defun insert-tabs (n)
"Inserts N number of tabs"
(interactive "nNumber of tabs: ")
(dotimes (i n)
(indent-for-tab-command)))
(global-set-key [?\C-x \C-tab] 'insert-tabs)
Run Code Online (Sandbox Code Playgroud)
Jac*_*lly 13
桑德罗答案的关键部分是打电话给indent-rigidly.
C-x TAB (translated from C-x <tab>) runs the command indent-rigidly,
which is an interactive compiled Lisp function in `indent.el'.
It is bound to C-x TAB.
(indent-rigidly start end arg)
Indent all lines starting in the region sideways by arg columns.
Called from a program, takes three arguments, start, end and arg.
You can remove all indentation from a region by giving a large negative arg.
Run Code Online (Sandbox Code Playgroud)
所以,标记区域,输入数字arg,按C-x TAB.
我认为以下代码可以帮助您:
;; Shift the selected region right if distance is positive, left if
;; negative
(defun shift-region (distance)
(let ((mark (mark)))
(save-excursion
(indent-rigidly (region-beginning) (region-end) distance)
(push-mark mark t t)
;; Tell the command loop not to deactivate the mark
;; for transient mark mode
(setq deactivate-mark nil))))
(defun shift-right ()
(interactive)
(shift-region 1))
(defun shift-left ()
(interactive)
(shift-region -1))
;; Bind (shift-right) and (shift-left) function to your favorite keys. I use
;; the following so that Ctrl-Shift-Right Arrow moves selected text one
;; column to the right, Ctrl-Shift-Left Arrow moves selected text one
;; column to the left:
(global-set-key [C-S-right] 'shift-right)
(global-set-key [C-S-left] 'shift-left)
Run Code Online (Sandbox Code Playgroud)
您可以将所需的值替换为(shift-region 1)和(shift-region 1).
编辑:正如你所看到的,我的函数包含了缩进:
indent-rigidly是`indent.el'中的交互式编译Lisp函数.
它与Cx TAB绑定.
(缩进刚刚开始结束)
通过ARG列缩小从区域侧面开始的所有行.从程序调用,需要三个参数,START,END和ARG.您可以通过提供较大的负ARG来删除区域中的所有缩进.