September 26, 2023, Tuesday afternoon
I have to say that installing plug-ins in emacs is indeed more convenient than vim.
Although I once said that I should only use vim, it is too troublesome to install plug-ins in vim.
Table of contents
- Emacs configuration file location under Linux
- package manager elpa
- How to change the source of elpa
- List of installable plugins
- How to search for plugins
- How to install plug-ins
- Configure plugin
Emacs configuration file location under Linux
The default configuration file location is ~/.emacs or ~/.emacs.d/init.el
If you don’t have inti.el, you can just create it yourself.
package manager elpa
Starting from Emacs 24, Emacs has built-in elpa package manager, which can automatically download and install plug-ins.
Emacs 24 was released in October 2011.
elpa stands for Emacs Lisp Package Archive package management system.
elpa uses MELPA (Marmalade Emacs Lisp Package Archive) as the default plug-in repository source.
How to change the source of elpa
According to the above web page, just add the following code to init.el:
(setq package-archives '(("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("nongnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/nongnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(package-initialize) ;; You might already have this line
List of installable plugins
First press Alt-x so that you can enter commands in Emacs.
Then enter the following command:
package-list-packages
Next, we will list various plug-ins.
How to search for plugins
Press Ctrl+s to search for plugins
How to install plug-ins
Press Alt+x and enter the following command:
package-install
Next enter the name of the plug-in you want to download
Configure plugin
After the plug-in is installed successfully, it needs to be configured accordingly in init.el to use it normally.
Each plug-in has different configurations. You can go to the official website of the plug-in or search elsewhere on the Internet for how a certain plug-in is configured.
For example, the official website of the company plug-in explains how to configure it.