• emacs 操作集锦


    1、C-k 的功能并不是剪切当前行,而是剪切当前行从光标到行末的内容。

    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 下 与系统系统剪切板相关的操作。

    ;;关于剪切板: X共享信息的有 clipboard primary secondary 三个区域;;其中clipboard 就是我们常说的剪切板,而primary 就是常说的selection ,也就是说只要你选中一段内容,;;那么这段内容就被存到primary 中了,而secondary 目前好像已经不推荐使用了,所以不用考虑;;而emacs 默认存在内容的区域不是上面任何一个,它叫kill-ring叫剪切环,它能存储不只一份内容,;;C-y 会取出kill-ring 中最近的一份内容,然后paste(专业点叫yank)到buffer 中,可以通过M-y;;取得以前的版本
    (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).

    ============================================================================================

    三、Emacs中文输入法切换设置
    Emacs中默认Ctrl+Space或Ctrl+@设置选择标记(set-mark). 这对非英语国家用户来说,不太方便。因为Windows下Ctrl+Space切换输入法。而在Emacs中按Ctrl+@又太累(要按Shift呀)。
    解决办法是:Emacs中改用Shift+Space设置标记(set-mark)。
    把下边这行加入到~/.emacs中:
    ;;; hzh add for set mark,我用的是prelude,所以这些应该放在prelude-modules.el里
    ;;; below add by hzh
    ;;; create a directory named ".emacs-hzh.d" in home dir, and put all your personal
    ;;; files(or directories) in it, we will add it to load-path. If you hava a theme,
    ;;; you should make a dir named "themes", and put theme files in it.
     
    (defun hzh-add-subfolders-to-load-path (parent-dir)
      "Add all level PARENT-DIR subdirs to the `load-path'."
      (dolist (f (directory-files parent-dir))
        (let ((name (expand-file-name f parent-dir)))
          (when (and (file-directory-p name)
                     (not (equal f ".."))
                     (not (equal f ".")))
            (add-to-list 'load-path name)
            (hzh-add-subfolders-to-load-path name)))))
     
    (defun hzh-add-subfolders-to-custom-theme-load-path (parent-dir)
      "Add all level PARENT-DIR subdirs to the `custom-theme-load-path'."
      (dolist (f (directory-files parent-dir))
        (let ((name (expand-file-name f parent-dir)))
          (when (and (file-directory-p name)
                     (not (equal f ".."))
                     (not (equal f ".")))
            (add-to-list 'custom-theme-load-path name)
            (hzh-add-subfolders-to-custom-theme-load-path name)))))
     
    (defvar hzh-emacs.d ".emacs-hzh.d")
    (defvar hzh-loadpath (expand-file-name hzh-emacs.d (getenv "HOME")))
    (defvar hzh-theme-loadpath (expand-file-name "themes" hzh-loadpath))
    (hzh-add-subfolders-to-load-path hzh-loadpath)
    (add-to-list 'custom-theme-load-path hzh-theme-loadpath)
    (hzh-add-subfolders-to-custom-theme-load-path hzh-theme-loadpath)
     
    ;; hzh add for theme
    (disable-theme 'zenburn)
    ;; (load-theme 'solarized-dark t t)
    ;; (enable-theme 'solarized-dark)
    ;; (load-theme 'monokai t t)
    ;;; (setq molokai-theme-kit t)
    (load-theme 'molokai t t)
    (enable-theme 'molokai)
     
    ;;; hzh add for ibus
    ;;; ibus-el 似乎使用的是python2
    (require 'ibus)
    (setq ibus-python-shell-command-name "python2.7")
    ;; Turn on ibus-mode automatically after loading .emacs
    (add-hook 'after-init-hook 'ibus-mode-on)
     
    ;;; hzh add for ibus settings
    ;; Use C-SPC for Set Mark command
    ;; (ibus-define-common-key ?C-s nil)
    ;; Use C-/ for Undo command, hzh: ibus will not change Undo
    (ibus-define-common-key ?C-/ nil)
    (ibus-define-common-key [?S- ] nil)
    ;; Change cursor color depending on IBus status
    (setq ibus-cursor-color '("red" "blue" "limegreen"))
    (global-unset-key (kbd "C-SPC"))
    (global-set-key (kbd "C-SPC") 'ibus-toggle)
     
    ;;; hzh add for set mark
    (global-set-key [?S- ] 'set-mark-command)
    (global-set-key (kbd "M-n") 'set-mark-command)
    ;(custom-set-variables '(default-input-method "chinese-py"))
     
    ;;; hzh add for scroll bar
    (toggle-scroll-bar -1)
     
    ;;; hzh add for line number
    (global-linum-mode t)
    (display-time-mode t)
     
    ;;; hzh add for goto-line
    (global-set-key [f8] 'goto-line)
     
    四、Emacs中文输入法切换设置
    输入法
    没有了中文输入法, Emacs 对於中文使用者一点用处都没有。想要知道您可以使用哪些输入法,您可以键入 C-x RET C- SPC ,接著 Emacs 会出现一个所有多国语文的输入法列表窗格。然后您就可以在其中键入您所使用的输入法名称了。下面是作者的作法:(作者使用的是行列输入法,名称为 chinese-array30 。)
     
    1. 设定预设的输入法,将下面这一行加入到 ~/.emacs 档案中:
     
    (custom-set-variables '(default-input-method "chinese-array30"))
     
    这样子在启动 Emacs 后,您就可以直接以 C- 指令在英文输入和行列输入法之间切换了。
     
    2. 但是有时候用行列打不出来,需要切换成注音输入法。   有两种方式可以达成这个目的:
     
       a. C-x RET C- chinese-zozy RET
       b. C-u C- chinese-zozy RET
     
    作者建议您使用第二种方式,因为它同时也是作为两种输入法间切换的指令。接下来您只要键入 C-u C- RET 就可以在行列和注音这两者间作切换了。(注意:中英输入法间的切换还是以 C- 指令为之。)
    以后我们在不同中文输入法间作切换将可以 C-u C-u C- 达成,原本作者是建议以 M- 来补足这个想法,但是 M- 很不幸已经作为 delete-horizontal-space 指令了。不然 C- 搭配 M- 不是很漂亮吗?
    这样子您应该可以理解如何使用中文输入环境了吧!当然,您必须将行列改为自己喜欢的输入法。
     
    如果您找不到自己喜欢的输入法,那么您可以:
     
    1. 自己造一个(相关文献在  .../emacs/leim/quail/ 。)
    2. 利用现成的输入法档案做出一个
       ( .../emacs/lisp/international/titdic-cnv.el 。)
       只要是 cxterm 的 *.tit 和 xcin 的 *.cin   有提供的输入法都可以。
       但是作法上对於终端使用者而言并不十分“自动”,   因此现阶段可能还是需要志愿者协助进行才有办法。
     
    不知道 cxterm 和 xcin 的开发人员是否可以协助提供。(对了, cxterm 的行列输入法有个小臭虫,应该和谁联系?)
     
    ======================================================================
     
    auto completion:
    M-/                       (hippie-expand)                        #(global-set-key (kbd "M-/")  'hippie-expand)


    Bookmark:
    C-x r m RET                              Set the bookmark for the visited file, at point.
    C-x r m bookmark RET            Set the bookmark named bookmark at point (bookmark-set).
    C-x r b bookmark RET            Jump to the bookmark named bookmark (bookmark-jump).
    C-x r l                                        List all bookmarks (list-bookmarks).
    M-x bookmark-delete RET bookmark RET                    Delete the bookmark named bookmark. 

    View Mode:
    M-x view-buffer prompts for an existing Emacs buffer, switches to it, and enables View mode. 
    Typing e (View-exit) disables View mode.

     
    Follow Mode:
    To use Follow mode, go to a frame with just one window,split it into two side-by-side windows using C-x 3, and then type M-x follow-mode.To turn off Follow mode, type M-x follow-mode a second time. 

     M-s        (
    sp-splice-sexp) unwrap the list, example:    (foo (bar| baz) quux) -> (foo bar| baz quux),附加的,与follow mode不相关。
     
    Multiple buffers:
    C-x b buffer RET                Select or create a buffer named buffer (switch-to-buffer).
    C-x C-b RET                        Popup a window to Select buffer (ibuffer). 
    C-x 4 b buffer RET            Similar, but select buffer in another window (switch-to-buffer-other-window).
    C-x 5 b buffer RET            Similar, but select buffer in a separate frame (switch-to-buffer-other-frame).
    C-x LEFT                            Select the previous buffer in the buffer list (previous-buffer).
    C-x RIGHT                         Select the next buffer in the buffer list (next-buffer).
    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-belowSplit 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 o                                 Select another window (other-window)     (包含 C-x O: 移动到上一个window,命令为 other-window -1)
    C-x 1                                 runs the command delete-other-windows
    C-x 4 b bufname RET     Select buffer bufname in another window (switch-to-buffer-other-window)
    C-x 4 f filename RET      Visit file filename and select its buffer in another window (find-file-other-window)
    C-x 4 r filename RET      Visit file filename read-only, and select its buffer in another window (find-file-read-only-other-window)
    C-x 4 d directory RET    Select a Dired buffer for directory directory in another window (dired-other-window) 
    C-x 4 0                             Delete the selected window and kill the buffer that was showing in it (kill-buffer-and-window)
    C-x ^                                 Make selected window taller (enlarge-window)
    C-x }                                 Make selected window wider (enlarge-window-horizontally)
    C-x {                                 Make selected window narrower (shrink-window-horizontally)
    C-x -                                 Shrink this window if its buffer doesn’t need so many lines (shrink-window-if-larger-than-buffer)
    C-x +                                 Make all windows the same height (balance-windows)
    C-u 10 C-x ^                    Make selected window taller (enlarge-window) with 10 lines(带参数的形式)

    Moving by Defuns:
    C-M-a                                Move to beginning of current or preceding defun (beginning-of-defun),就是移动到函数头
    C-M-e                                 Move to end of current or following defun (end-of-defun),移动到函数尾部
    C-M-h                              Put region around whole current or following defun (mark-defun),选择整个函数
     
    Imenu:
    M-x imenu                       it reads the name of a definition using the minibuffer, then moves point to that definition.寻找函数定义位置

    Indenting Several Lines:
    C-M-q                         Reindent all the lines within one parenthetical grouping(c-indent-exp),即在光标移到{上,然后按键

    Searching with Grep under Emacs:
    M-x lgrep                      异步查找
    M-x grep                      在当前目录进行grep, 
    M-x grep-find                find and grep
    M-x find-grep                find and grep
    M-x rgrep                      find and grep
    M-x kill-grep                    Kill the running grep subprocess 

    Running Compilations under Emacs:
    M-x compile             Run a compiler asynchronously under Emacs, with error messages going to the *compilation* buffer
    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 
    If you change the variable compilation-auto-jump-to-first-error to a non-nil value, Emacs automatically visits the locus of the first error message that appears in the *compilation* buffer. 
    Running Debuggers Under Emacs:
    The GUD (Grand Unified Debugger) library provides an Emacs interface to a wide variety of symbolic debuggers. It can run the GNU Debugger (GDB), as well as DBX, SDB, XDB, Perl’s debugging mode, the Python debugger PDB, and the Java Debugger JDB.
    M-x gdb        
    M-x gdb-many-windows             works after M-x gdb 
    C-x SPC                                        Set a breakpoint on the source line that point is on (gud-break), 必须在gdb minor模式用
    (附注: gdb 里设置LD_LIBRARY_PATH的方法:   set  environment  LD_LIBRARY_PATH  ****)
    (gdb>  set args xxx   #給執行程式參數xxx,必须在run之前;   或者 gdb>  run param1 param2 param3)
    (gdb> ptype ***valuavle)    # print out the definition of a struct or class
    (gdb> print *(struct mystruct *)  0x8002bf20) #可以pretty打印某个struct的内容

    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

    良辰美景补天漏,风雨雷电洗地尘
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • 相关阅读:
    vue实例讲解之axios的使用
    实例讲解webpack的基本使用第四篇
    实例讲解webpack的基本使用第三篇
    实例讲解webpack的基本使用第二篇
    写好一篇技术博客的正确姿势是什么
    实例讲解js正则表达式的使用
    一个综合实例讲解vue的基础知识点。
    vue实例讲解之vue-router的使用
    .NET 串口通信
    textarea赋值时换行符无效的解决方法
  • 原文地址:https://www.cnblogs.com/welhzh/p/3549257.html
Copyright © 2020-2023  润新知