一、如何上下移动某行?
(defun move-text-internal (arg)
(cond((and mark-active transient-mark-mode) (if (> (point) (mark)) (exchange-point-and-mark)) (let ((column (current-column)) (text (delete-and-extract-region (point) (mark)))) (forward-line arg) (move-to-column column t) (set-mark (point)) (insert text) (exchange-point-and-mark) (setq deactivate-mark nil))) (t (beginning-of-line) (when (or (> arg 0) (not (bobp))) (forward-line) (when (or (< arg 0) (not (eobp))) (transpose-lines arg)) (forward-line -1)))))
(defun move-text-down (arg)
“Move region (transient-mark-mode active) or current line
arg lines down.”
(interactive “*p”)
(move-text-internal arg))(defun move-text-up (arg)
“Move region (transient-mark-mode active) or current line
arg lines up.”
(interactive “*p”)
(move-text-internal (- arg)))(global-set-key [M-up] 'move-text-up)
(global-set-key [M-down] 'move-text-down)
按alt+上下方向键即可。
二、如何在当前行上面再开一行?
C-a C-o
或者自定义:
;; Behave like vi's O command(defun open-previous-line (arg) "Open a new line before the current one. See also `newline-and-indent'." (interactive "p") (beginning-of-line) (open-line arg) (when newline-and-indent (indent-according-to-mode)))```
(global-set-key [C-S-return] 'open-previous-line)` <br /><pre>只需要按Ctrl+Shirt+enter即可。
`
三、如何快速在当前行下面新开一行,并且光标移到新行?
C-e
或者自定义:
;; Behave like vi's o command(defun open-next-line (arg) "Move to the next line and then opens a line. See also `newline-and-indent'." (interactive "p") (end-of-line) (open-line arg) (next-line 1) (when newline-and-indent (indent-according-to-mode)))```
(global-set-key [S-return] 'open-next-line)` <br /><pre>只要按ctrl+enter即可。
`
四、如何将当前行复制一遍,插入到新一行?
C-a C-k C-k C-y C-y
五、当光标停在某个括号的一头时,如何让另一头高亮显示?
在.emacs中加入:
(show-paren-mode 1)
六、当光标停在某个括号的一头,如何跳转到另一头?
TODO
七、如何将下一行合并在当前行的结尾?
C-e C-k
八、如何让光标跳到下一个单词的第一个字母?
能否用一个快捷键,跳到User的U上?
TODO
九、如何快速调整当前行缩进?
能否用一个快捷键,就让当前行的缩进正常?
通常情况下,直接按tab键
十、连按三次esc.esc.esc才能取消命令,经常个数按错,有没有哪个快捷键只用按一次?
TODO
十一、在gui模式下,如何用快捷键让emacs窗口最大化?
TODO
十二、选中一些文字后,如何快速删除?
在.emacs中加入这段:
(delete-selection-mode t)
然后就可以按ctrl-d, DEL, Backspace来删除选中的文字了。
十三、如何快速格式化整个文件,并且保持光标位置不变?
通常用:
c-x h c-m-\
麻烦不说,光标还会跳到文件开头。在.emacs中加入以下代码,即可一键搞定:
(defun indent-current-buffer ()
(interactive) (indent-region (point-min) (point-max))) (global-set-key (kbd "C-S-f") 'indent-current-buffer) **十四、如何只使用空格缩进?** emacs默认情况下,同时使用tab和space进行缩进。有时候不太方便,比如把代码贴到stackoverflow上调整缩进。 这时要在.emacs中加入下句:
(setq-default indent-tabs-mode nil)
十五、如何在启动时不显示初学者教程?
加入:
;; Remove splash screen
(setq inhibit-splash-screen t)