emacs 操作集锦
Emacs 中的剪切不叫剪切(cut),叫kill,复制(copy)不叫copy ,叫kill-ring-save (这个可以理解为先kill掉放到kill-ring里,然后再把它save回来)。另外还有一个操作叫delete ,delete 与kill的区别是kill掉的内容会被放到kill-ring(剪切环)而delete掉的内容则直接删掉了,除了进行undo操作外没法找回删掉的内容。而kill 掉的内容很容易从kill-ring中取回。有了kill-ring的Emacs可以说是具有了多个剪贴板。
默认的与kill yank delete 有关的键绑定。
- C-w kill-region
- C-k kill-line
- C-M-k kill-sexp 这个比较复杂 它表示删除一个结构单元。对不同类型的文档(c java文本 等)一个结构单元表示不同的含义。你可以尝试一下。(比如,你移动到一个括号的开头,按下,则删除整个括号内的内容)
- C-d delete-char
- M-d kill-word
- C-backspace backward-kill-word
- M-w kill-ring-save 复制。
- C-y yank 粘贴。
- 另外在按下C-y后,按一次或多次M-y 会循环取出kill-ring中的内容,然后贴到当前位置 。
- 但是kill-ring毕竟不是操作系统的剪切板,kill-ring里的内容是没法在其他程序里利用的。所以要用好它又设及到与系统剪切板的同步的问题了。 在Windows 上Emacs已经默认解决了这个问题。在linux上没有。因为Linux的剪切板不只一个。所以问题要复杂许多。
Linux 下 与系统系统剪切板相关的操作。
(defun setting-for-linux-x-clipboard (&optional frame)
(when (and (eq system-type 'gnu/linux)(eq (window-system frame) 'x))
;;在向kill-ring 加入内容的同时会执行interprogram-cut-function 变量指定的函数
(setq-default interprogram-cut-function 'x-select-text);
; default ;;在执行yank 操作时,会检查interprogram-paste-function 变量 所指向的函数 ;;是否有返回值,如果有的话就将其yank在buffer 中,否则的话才会从kill-ring中取值 ;;而x-cut-buffer-or-selection-value 和x-select-text函数一样, ;;也会根据x-select-enable-clipboard 和x-select-enable-primary 的值 ;;决定是否从clipboard 和primary 中取得内容
(setq-default interprogram-paste-function 'x-cut-buffer-or-selection-value)
;;有关于往kill-ring加入内容时 是否往clipboard ,及primary 放入的判断
(setq-default x-select-enable-clipboard t)
;每一次往kill-ring 里加入东西时,同时往clipboard中放一份,
(setq-default x-select-enable-primary nil)
;每一次往kill-ring 里加入东西时,是否也往primary 中放入
(setq-default select-active-regions t)
;这个忘了什么意思 ;;在轮询kill-ring 的时候是否也同步改变系统的clipboard primary ;;(要根据x-select-enable-clipboard ,及x-select-enable-primary的值决定哪个会被改变)
(setq-default yank-pop-change-selection t)
;;;Save clipboard strings into kill ring before replacing them
(setq-default save-interprogram-paste-before-kill t)
;; make mouse middle-click only paste from primary X11 selection, not clipboard and kill ring. ;;鼠标中键粘贴,只考虑X11中的selection ,不考虑clipboard 和emacs 中的kill-ring
(global-set-key [mouse-2] 'mouse-yank-primary)
;;其实有了以上几个配置 下面这三个键完全没有必要,但为防万一, ;;将与剪切板相关的三个操作绑到这三个不常用的键上.
(global-set-key [(shift delete)] 'clipboard-kill-region)
(global-set-key [(control insert)] 'clipboard-kill-ring-save)
(global-set-key [(shift insert)] 'clipboard-yank) ) )
=============================================================================================
二、set key Bindings
M-x global-set-key <RET> key cmd <RET>
Define key globally to run cmd. example: M-x global-set-key <RET> C-z shell <RET>
M-x local-set-key <RET> key cmd <RET>
Define key locally (in the major mode now in effect) to run cmd.
M-x global-unset-key <RET> key
Make key undefined in the global map.
M-x local-unset-key <RET> keyMake key undefined locally (in the major mode now in effect).
============================================================================================
Bookmark:
C-x r m RET Set the bookmark for the visited file, at point.
M-x bookmark-delete RET bookmark RET Delete the bookmark named bookmark.
View Mode:
Typing e (View-exit) disables View mode.
Follow Mode:
M-s (sp-splice-sexp) unwrap the list, example: (foo (bar| baz) quux) -> (foo bar| baz quux),附加的,与follow mode不相关。
Multiple buffers:
C-x C-b RET Popup a window to Select buffer (ibuffer).
C-x k C-x k runs the command ido-kill-buffer
C-x b buffername C-k kill buffer in background
Multiple windows:
C-x 2 (split-window-below) Split the selected window into two windows, one above the other
C-x 3 (split-window-right) Split the selected window into two windows, positioned side by side
C-x 4 d directory RET Select a Dired buffer for directory directory in another window (dired-other-window)
C-M-h Put region around whole current or following defun (mark-defun),选择整个函数
Imenu:
Indenting Several Lines:
M-x lgrep 异步查找
M-x grep 在当前目录进行grep,
Running Compilations under Emacs:
M-x recompile Invoke a compiler with the same command as in the last invocation of M-x compile
M-x kill-compilation Kill the running compilation subprocess
M-x gdb
M-x gdb-many-windows works after M-x gdb
Dired, the Directory Editor:
Dired makes an Emacs buffer containing a listing of a directory, and optionally some of its subdirectories as well. You can use the normal Emacs commands to move around in this buffer, and special Dired commands to operate on the listed files.
C-x C-d (list-directory) list files in a directory, but it is not Dired
C-x d (dired) invoke Dired
Reading Mail with Rmail:
支付宝扫一扫捐赠
微信公众号: 共鸣圈
欢迎讨论,邮件: 924948$qq.com 请把$改成@
QQ群:263132197
QQ: 924948