emacs

Powerful full-screen text editor

Supplementary instructions

emacs command is a powerful full-screen text editor developed by Richard Stallman, the founder of the GNU organization. It supports multiple programming languages and has many excellent features. There are numerous system administrators and software developers using emacs.

grammar

emacs(options)(parameters)

Options

+<line number>: Start the emacs editor and move the cursor to the line where the line number is specified;
-q: Start the emacs editor without loading the initialization file;
-u<user>: When starting the emacs editor, load the initialization file of the specified user;
-t<file>: When starting the emacs editor, the specified file is used as the middle end, and standard input (stdin) and standard output (stdout) are not applicable;
-f<function>: Execute the specified lisp (programming language widely used in the field of artificial intelligence) function;
-l<lisp code file>: Load the specified lisp code file;
-batch: Run the emacs editor in batch mode.

Parameters

File: Specify the text file to edit.

emacs command operation list

basic commands

C-x C-c : Exit Emacs
C-x C-f: Open a file or create one if it does not exist
C-g: Cancel unfinished command

edit

C-z (redefined): Undo; it turns out that C-z suspends Emacs (and then calls it out with the fg command); C-x u is the default command; move the cursor and then C-z can redo
M-d: Delete the word after the cursor

Move cursor

C-v: page forward
M-v: page backward
M-r: Move the cursor to the line in the middle of the screen
C-a: move to the beginning of the line
M-a: Move to the beginning of the sentence. There may be spaces between the beginning of the line and the beginning of the sentence.
C-e: move to the end of the line
M-e: move to the end of the sentence
M-{: move up a section
M-}: Move down a section
C-right: move forward one word
C-left: Move backward one word
C-up: move forward a step
C-down: move backward a step
M-< : Move to the beginning of the entire text
M->: Move to the end of the entire text
C-u numeric command: execute the command multiple times (the number indicates the number of times); "M-numeric command" can also be used
M-x goto-line: move to a certain line
C-l: Redraw the screen. The effect is to move the current editing line to the center of the window.

Buffer related

C-x k: close the current buffer
C-x b: switch to the previously edited buffer
C-x C-b: List all current buffers
C-x C-s: save current buffer
C-x s: Save all unsaved buffers, you will be prompted whether you need to save them
C-x C-w: Save file as

Copy and paste

M-space (redefined): set mark; C-@ is the default command
C-w (redefined): Cut an area; if mark is not set, it will cut a line
M-w (redefined): Copy an area; if mark is not set, copy a line
C-k: Cut from the current position to the end of the line
C-y : Paste
M-y: After using C-y to pull back the recently removed text, change to M-y to pull back the previously removed text. Type M-y multiple times to bring back previously removed text.
C-x r k: perform clipping of a rectangular area
C-x r y: Paste a rectangular area
window operations
C-x 0: Close the current window
C-x 1: Maximize the current window
C-x 2: split window vertically
C-x 3: split window horizontally
M-o (redefined): switch between windows; C-x o is the default command
C-x 5 1/2/3/0: Similar operations on frame
C-x < : Scroll window content right
C-x >: Scroll window content to the left (these two commands are more useful after splitting the window vertically)
(C-u) C-x ^: Heighten the current window. If C-u is present, heighten 4 lines at a time.
(C-u) C-x } : Widen the current window
(C-u) C-x { : Narrow the current window
ESC C-v: scroll the screen in other windows

Search and replace

C-s: forward search (incremental search); continuous C-s, jump to the next searched target
C-s RET: normal search
C-r: search forward
C-s RET C-w: query by word
M-%: Query and replace, that is, it will ask before replacing.
M-x replace-string: ordinary replacement

Tags

M-! etags .c .h: Create TAGS file
M-.: Jump to the location of tag
M-x list-tags: list tags

bookmark

C-x r m: set bookmark bookmark
C-x r b: jump to bookmark

help

C-h ? : View help information
C-h f : View a function
C-h v : View a variable
C-h k: View a key binding (C-h c also views the key binding, but the information is simpler)
C-h C-f: View the info of a function, very useful
C-h i: View Info

other

C-M-\: Format the selected area according to a certain format (such as C program)
C-x h : select all
M-! : Execute external shell command
M-x shell: simulate shell buffer
M-x term: simulate terminal, C-c k close terminal
C-x C-q: Modify the read-only attribute of the buffer