emacs-guides icon indicating copy to clipboard operation
emacs-guides copied to clipboard

Learn about Emacs.

  • Emacs Guides This repository saved the basic usage of GNU/Emacs and personal experiences of members of the studio.

    PS: More practice are not just look at sentences, it's can helps you learn quickly!

    PSS: Emacs Document is your good friend, ~C-h f~ for functions document, ~C-h v~ for variables document, ~C-h k~ for keybindings document.

    [[./README_cn.org][中文版]]

** Table of Contents

  • [[#contributors][Contributors]]
  • [[#basics-in-basic][Basics in Basic]]
    • [[#explore-files][Explore Files]]
    • [[#number-argument][Number Argument]]
    • [[#disabled-commands][Disabled Commands]]
    • [[#file-operations][File Operations]]
    • [[#buffer-operations][Buffer Operations]]
    • [[#window-management][Window Management]]
    • [[#search][Search]]
  • [[#configuration-file][Configuration File]]
    • [[#emacs-lisp][Emacs Lisp]]
    • [[#recommended-settings][Recommended Settings]]
  • [[#references][References]]
  • [[#license][License]]

** Contributors Thanks all contributors about this repository! (Rank order of contribution date) | Contributors | Emacs Configuration File Repository | |--------------+--------------------------------------| | [[https://github.com/KiteAB][KiteAB]] | [[https://github.com/KiteAB/.emacs.d][.emacs.d]] |

Contributors must view [[./todo.org][todo.org]] then edit files.

** Basics in Basic In Emacs, we have a rule: | Keybindings | Means | |-------------+--------------------------------------------------------| | ~C-~ | Press control key when entering the ~~ character | | ~M-~ | Press alt key when entering the ~~ character | | ~s-~ | Press super key when entering the ~~ character |

Example: #+begin_example C-f means press control and enter "f" character M-x means press alt and enter "x" character s-a means press super and enter "a" character (Seldom used) #+end_example

And you sometimes encounter multiple consecutive key combinations, example: ~C-x C-c~ to exit the Emacs.

If you want to exit some running command, use ~C-g~ to exit them.

You can try press ~M-x~ key, It'll open a "toolbox", you can find all Emacs command in it.

*** Explore Files You can use ~C-f~ ~C-b~ ~C-n~ ~C-p~ keybindings to move cursor slowly: | Keybindings | Actions | |-------------+-----------------| | ~C-f~ | Forward a char | | ~C-b~ | Backward a char | | ~C-n~ | Next line | | ~C-p~ | Previous line |


And you can use ~M-f~ ~M-b~ to move cursor by words: | Keybindings | Actions | |-------------+-----------------| | ~M-f~ | Forward a word | | ~M-b~ | Backward a word |


What? Not fast enough? Try page up or page down by ~C-v~ ~M-v~: | Keybindings | Actions | |-------------+-----------| | ~C-v~ | Page Down | | ~M-v~ | Page Up | (Alternatively, you can still use the ~<PGUP>~ and ~<PGDN>~ keys to page up and down)


If you want the current line in a different location on the screen, you can use ~C-l~: | Keybindings | Actions | |---------------------+------------------------------------------| | ~C-l~ (first time) | Re-center current line | | ~C-l~ (second time) | Put current line to top in the screen | | ~C-l~ (third time) | Put current line to bottom in the screen |


~C-a~ ~C-e~ ~M-a~ ~M-e~ can help you fast move cursor to beginning of line or end of line, sentences can do that too: | Keybindings | Actions | |-------------+-----------------------| | ~C-a~ | Beginning of line | | ~C-e~ | End of line | | ~M-a~ | Beginning of sentence | | ~M-e~ | End of sentence |


And ~M-<~ ~M->~ is the fastest: | Keybindings | Actions | |-------------+---------------------| | ~M-<~ | Beginning of buffer | | ~M->~ | End of buffer |

*** Number Argument You can add a number argument for some commands. | Keybindings | Actions | |-------------------+-------------------------------| | ~C-u ~ | Execute ~~ times ~~ | Here is an example: #+begin_example "C-u 8 C-n" means do "C-n" 8 times, which's cursor down 8 lines. "C-u 8 *" will insert "********" #+end_example

*** Disabled Commands Emacs has some disabled commands, they're dangerous commands, so Emacs disabled it.

If you press ~C-x C-n~, Emacs will create a buffer named ~*Disabled Command*~, and you can enter ~y~ to enable this command or ~n~ to continue disable it.

*** File Operations | Keybindings | Actions | |-------------+------------------------------------------------------------------| | ~C-x C-s~ | Save current buffer to correspond file | | ~C-x s~ | Save multiple buffers to the corresponding file at the same time | | ~C-x C-f~ | Find a file and open it |

*** Buffer Operations You must understand the difference between ~delete~ and ~remove~, ~delete~ is remove characters directly, but ~remove~ will cut the characters to clipboard, so you can recall it. | Keybindings | Actions | |------------------------+-----------------------------------------------------------------| | ~C-x b~ | Switch buffer | | ~C-x k~ | Kill buffer | | ~<DEL>(DELETE key)~ | Delete a character before the cursor | | ~C-d~ or ~<BACKSPACE>~ | Delete a character after the cursor | | ~M-<DEL>~ | Remove a word before the cursor | | ~M-d~ | Remove a word after the cursor | | ~C-k~ | Remove from between the character cursor to the end of line | | ~M-k~ | Remove from between the character cursor to the end of sentence | | ~C-@~ or ~C-<SPC>~ | Selecting characters | | ~M-w~ | Copy selected characters | | ~C-w~ | Cut selected characters | | ~C-y~ | Paste characters in clipboard | | ~C-k~ (first time) | Remove current line (Don't remove line breaks) | | ~C-k~ (second time) | Remove line breaks | | ~C-/~ or ~C-_~ | Undo or Redo | | ~C-x u~ | Undo only |

*** Window Management You can use some keybindings to manage your windows in Emacs. | Keybindings | Actions | |-------------+-----------------------------------| | ~C-x 0~ | Close current window (Not buffer) | | ~C-x 1~ | Leaving only the current window | | ~C-x 2~ | Horizontal split a window | | ~C-x 3~ | Vertical split a window | | ~C-x o~ | Switch to next window |

*** Search Use ~C-s~ to down search and ~C-r~ to up search.

** Configuration File In general, we need to configure the editing experience suited to their profiles to get better.

Emacs configuration files are usually stored at home directory ~.emacs.d~ folder, the file structure similar to the following settings: #+begin_example

  • .emacs.d
    • init.el ; Emacs retrieves the file to launch the default
    • elpa ; Emacs will download the package in here
    • etc ; Although not required, it is recommended that the personal configuration file on here #+end_example

*** Emacs Lisp To configure your own Emacs configuration file, you need to know what's Emacs Lisp and how to use it.

Programming experts usually just look at the code fragment can probably understand a programming language:
#+begin_src emacs-lisp
(+ 1 1) ; 1 + 1
(+ 1 2 (* 2 3)) ; 1 + 2 + ( 2 * 3 )

(setq name "Emacs Lisp") ; Variable
(setq list '("1" "2" "3")) ; List
(car list) ; First value extraction list
(cdr list) ; Extracting all but the first value in the variable
(add-to-list 'list "thing")
(add-to-list 'load-path "path-to-path") ; Load Emacs Lisp files in path
(require 'name) ; Require feature
(provide 'name) ; Provide feature
(push "thing" list) ; Push to list
(defun hello (myname) ; Define function
  "Function's document"
  (message "Hello, %s!" myname)) ; Will display "Hello, Emacs Lisp!" at mini-buffer
(hello name) ; Execute function
#+end_src
BTW: mini-buffer is a blank area below the status bar for displaying messages and documents.

*** Recommended Settings #+begin_src emacs-lisp ;; UI Settings (menu-bar-mode -1) ; Close the menu bar (tool-bar-mode -1) ; Close the tool bar (setq tab-bar-show nil) ; Always not display tab bar (scroll-bar-mode -1) ; Close Scroll bar (tab-bar-mode -1) ; Set tab bar not display (global-hl-line-mode t) ; Highlight current line (setq display-line-numbers-type 'relative) ; Relative numbers for display numbers mode (global-display-line-numbers-mode t) ; Set the line numbers (toggle-frame-fullscreen) ; Set fullscreen (setq inhibit-splash-screen t) ; Close the startup screen

;; Other Basic Settings
(fset 'yes-or-no-p 'y-or-n-p) ; Change the asking's answer way
(show-paren-mode t) ; Highlight the "()"
(electric-pair-mode t) ; Auto complete the "()"
(setq electric-pair-pairs
      '((?\" . ?\")
        (?\( . ?\))
        (?\< . ?\>)
        (?\{ . ?\}))) ; Set the electric-pair-mode's pair keywords
(setq make-backup-files nil ; Don't let Emacs make up backup file
      create-lockfiles nil ;Don't make lockfile
      auto-save-default nil ; Don't auto save the file
      )
(setq-default tab-width 2) ; The tab width
(setq-default indent-tabs-mode nil) ; Use space indent
(setq user-emacs-directory "~/.emacs.d/var") ;;; The Cache Directory
(setq user-init-file "~/.emacs.d/var/user-init.el")
(save-place-mode t) ; Save the point position
(setq ring-bell-function 'ignore blink-cursor-mode nil) ; Disable Infos
(setq scroll-step 2
      scroll-margin 2
      hscroll-step 2
      hscroll-margin 2
      scroll-conservatively 101
      scroll-up-aggressively 0.01
      scroll-down-aggressively 0.01
      scroll-preserve-screen-position 'always) ; Scroll
#+end_src

** References Emacs Tutorial: ~C-h t~ in Emacs, Emacs built-in tutorial

Learn X in Y Minutes, X = Elisp: https://learnxinyminutes.com/docs/zh-cn/elisp-cn

Recommended Settings: https://github.com/SpringHan/.emacs.d/blob/master/etc/settings/init-basic.el

** License GPL-3.0