Skip to content

KiteAB/emacs-guides

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

中文版

Table of Contents

Contributors

Thanks all contributors about this repository! (Rank order of contribution date)

ContributorsEmacs Configuration File Repository
KiteAB.emacs.d

Contributors must view todo.org then edit files.

Basics in Basic

In Emacs, we have a rule:

KeybindingsMeans
C-<char>Press control key when entering the <char> character
M-<char>Press alt key when entering the <char> character
s-<char>Press super key when entering the <char> character

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)

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:

KeybindingsActions
C-fForward a char
C-bBackward a char
C-nNext line
C-pPrevious line

And you can use M-f M-b to move cursor by words:

KeybindingsActions
M-fForward a word
M-bBackward a word

What? Not fast enough? Try page up or page down by C-v M-v:

KeybindingsActions
C-vPage Down
M-vPage 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:

KeybindingsActions
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:

KeybindingsActions
C-aBeginning of line
C-eEnd of line
M-aBeginning of sentence
M-eEnd of sentence

And M-< M-> is the fastest:

KeybindingsActions
M-<Beginning of buffer
M->End of buffer

Number Argument

You can add a number argument for some commands.

KeybindingsActions
C-u <num> <cmd>Execute <num> times <cmd>

Here is an example:

"C-u 8 C-n" means do "C-n" 8 times, which's cursor down 8 lines.
"C-u 8 *" will insert "********"

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

KeybindingsActions
C-x C-sSave current buffer to correspond file
C-x sSave multiple buffers to the corresponding file at the same time
C-x C-fFind 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.

KeybindingsActions
C-x bSwitch buffer
C-x kKill 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-dRemove a word after the cursor
C-kRemove from between the character cursor to the end of line
M-kRemove from between the character cursor to the end of sentence
C-@ or C-<SPC>Selecting characters
M-wCopy selected characters
C-wCut selected characters
C-yPaste 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 uUndo only

Window Management

You can use some keybindings to manage your windows in Emacs.

KeybindingsActions
C-x 0Close current window (Not buffer)
C-x 1Leaving only the current window
C-x 2Horizontal split a window
C-x 3Vertical split a window
C-x oSwitch 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:

- .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

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:

(+ 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

BTW: mini-buffer is a blank area below the status bar for displaying messages and documents.

Recommended Settings

;; 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

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

About

Learn about Emacs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published