Emacs basic usage

From wikinotes

Documentation

digitalocean tutorial https://www.digitalocean.com/community/tutorials/how-to-use-the-emacs-editor-in-linux


Commandline

emacs      # load gui emacs
emacs -nw  # load tui emacs

Modes

  • major-mode (generally associated with language. only one active at a time)
  • minor-mode (multiple minor modes can be activated at once)

emacs uses modes associated with different languages. (like filetypes in vim).

M-x       # set a major or minor mode (ex:  python-mode, c-mode, java-mode, ...)
# major modes
python-mode
java-mode

# minor modes
line-number-mode: This toggles the display of current line number in the status bar.
menu-bar-mode: This can switch the main menu on or off.

Command

Alt-x  # enter command (enter) - then pass arguments
;; Commands

goto-line  ;; go to line
term       ;; A full terminal-emulator. You can even run vim.
eshell     ;; LISP shell (emulates coreutils like ls, find but can evaluate LISP)
ielm       ;; Simply Access Lisp Interpreter


Basics

Files

Ctrl-x s        # save (as current name)
Ctrl-x w        # save (indicate name)
Ctrl-x, Ctrl-f  # open file
Ctrl-x Ctrl-c   # close

Navigation

# ========
# vertical
# ========
Ctrl-n/p    # line (prev/next)
Alt-</>     # buffer (start/end) (use shift)
Alt/Ctrl-v  # page (up/down)


# ==========
# horizontal
# ==========
Ctrl f/b   # char (fwd/bkwd)
Alt-f/b    # word (fwd/bkwd)
Ctrl a/e   # line (start/end)

Buffers

Ctrl-x, b       # switch buffer
Ctrl-x, Ctrl-b  # list buffers
Ctrl-x, o       # toggle buffer selection (switch panes)

Misc

Ctrl-space      # selection (mark start/finish)
Ctrl-s/r        # search (down/up)

# ====
# menu
# ====
F10             # open file-menu
Esc,Esc,Esc     # exit file-menu
Ctrl-h,r        # emacs help manual

# =========
# undo/redo
# =========
Ctrl-x u        # undo
Ctrl-/          # redo

# ===========
# copy/paste
# ===========
E-w             # copy
Ctrl-w          # cut
Ctrl-y          # yank

Ctrl k          # (kill) remove line until \n
Ctrl y          # paste all killed lines

Text

Alt-c           # capitalize word after cursor
Alt-u/l         # word (upper/lower case)