惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
D
DataBreaches.Net
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
S
Secure Thoughts
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
V2EX - 技术
V2EX - 技术
腾讯CDC
GbyAI
GbyAI
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
Help Net Security
Help Net Security
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
MongoDB | Blog
MongoDB | Blog
Scott Helme
Scott Helme
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
H
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
S
Security Affairs
TaoSecurity Blog
TaoSecurity Blog
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
Martin Fowler
Martin Fowler
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN Mintty Tips and Configurations Generating Table of Contents for Markdown with Tagbar Convert Python Script to Exe on Windows with Pyinstaller Ubuntu on Windows Missing after Windows Update 使用代理加速 Mac 终端下载速度 My Experience with Several Zsh Plugin Managers 深圳租房小记 How to Install zplug inside Docker Container Why don't settings inside bashrc or bash_profile take effect? Setting Up Locale in Linux 谷歌 Adsense 申请及在 Hugo 中的配置 How to Write Algorithm Pseudo Code in LaTeX Nifty Nvim Techniques That Make My Life Easier -- Series 4 A Few Grammar Questions in Writing How to Read and Write Images with Unicode Paths in OpenCV Creating A Professional Table in LaTeX with booktabs How to Create Proper Folding for Vim/Nvim Configuration Linux Tips and Tricks -- s1 JPEG Image Orientation and Exif How Do I Show the Current File Path In Neovim? JPEG Image Quality in PIL Difference between view, reshape, transpose and permute in PyTorch Convert PIL or OpenCV Image to Bytes without Saving to Disk Fast Movement and Navigation Inside Vim or Neovim Unintuitive Behaviour of Case Sensitivity in Python glob Binding Keys in Zsh 几把机械键盘试用体验 Nvim Autocompletion with Deoplete Converting Markdown to Beautiful PDF with Pandoc Exclusive and Inclusive Motion in Neovim/Vim Nifty Nvim Techniques Which Make My Life Easier -- Series 3 Why Doesn't Jedi Autocompletion Work for Some Methods Vim-like Editing inside Browser Markdown 生成 HTML 时汉字之间出现多余空格问题 小米 9 安装谷歌商店(Google Play Store)与相关配置 Create Mappings That Take A Count in Neovim Spell Checking in Nvim English Words Completion inside Neovim/Vim How to Use Python Inside Vim Script with Neovim Nifty Little Nvim Techniques to Make My Life Easier -- Series 2 Setting up Ultisnips for Neovim Mac 上罗技 M590 鼠标设置 Nifty Little Nvim Techniques to Make My Life Easier -- Series 1 A Complete Guide on Writing LaTeX with Vimtex in Neovim Manipulating Images with Alpha Channels in Pillow Sublime Text Regular Expression Cheat Sheet Cropping Rotated Rectangles from Image with OpenCV Boosting Your Productivity on Terminal with Zsh and Plugins 最新版 Rime 输入法使用 (2022 更新) Display Image with Pillow inside Ubuntu on Windows Faster Directory Navigation with z.lua Cmder Advanced Configurations Nvim-qt Settings on Windows 10 Tmux Plugin Install and Management How to Debug Python Code in Terminal Markdown Writing and Previewing in Neovim -- A Complete Guide Line Number Settings for More Efficient Movement in Neovim 两个大规模中文语料库介绍以及处理 Windows 系统下几款程序员不可不用的神器 我的 2018 阅读清单 A Complete Guide to Neovim Configuration for Python Development How Is Newline Handled in Python and Various Editors? Two Issues Related to ImageFont Module in PIL 在 Listary 中调用 GoldenDict 或欧路词典查单词 Reading and Writing Text Files on Windows The Mathematics behind Font Shapes --- Bézier Curves and More 快速识别图片字体:字体识别工具介绍 Deoplete Failed to Load at Startup after Updating Python neovim Package What Is The Difference between pip, pip3 and pip3.6 Shipped with Anaconda3? Windows 10 系统下 Neovim 安装与配置
Learning Emacs as A Nvimmer in One Day
2021-09-12 · via jdhao's digital space
update log

2021-11-24: Add more detailed instructions for installing doom-modeline.

I have been using Neovim for over three years and I have been constantly hearing the greatness of its rival editor Emacs. So today I am gonna to try it and see if it is truly great.

Edit: My final Emacs conf is here.

Install#

Check here: https://www.gnu.org/software/emacs/download.html

For Windows, go to this mirror site, and download emacs-27.2-x86_64.zip and extract it.

For macOS, use homebrew to install Emacs-plus1:

brew tap d12frosted/emacs-plus
brew install emacs-plus

How to Run?#

  • Windows: Go to extracted folder, run bin/runemacs.exe.
  • macOS: Run emacs from command line or search Emacs.app and run it.

Note to run emacs in maximized window, add following config to emacs config file:

(add-to-list 'initial-frame-alist '(fullscreen . maximized))

Ref:

Config file#

Emacs uses~/.emacs.d/init.el as its startup file (~/.config/emacs/init.el is also supported). Its configuration is written via a dialect of Lisp language called Emacs Lisp, or Elisp in short.

To check config file path, run C-H v user-init-file RET (RET is return key).

Reload config: note that it is not possible to entirely reload config, the best way is to restart your emacs. Open init.el, and run m-x eval-buffer.

Ref:

Install packages#

I am not a purist guy which only uses the built-in features of and editor and refuses to add plugins or packages.

Package is to Emacs what plugin is to Vim.

The built-in way#

To install packages, run M-x package-install, we are prompted to type the package name we want to install. Type the package name, and the package shall be installed.

Sometimes, due to bad network connection, emacs hangs forever when trying to connect to its package repo, and we see the following message:

Contacting host: elpa.gnu.org:443

In this case, we can change the package repo URL (add it to init.el)

;; this is just an example
(setq package-archives '(("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
                         ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))

One disadvantage of using built-in package management is that it can not install a package automatically if its hasn’t been installed. We need to write a few lines of code in config file.

Using 3rd party package manager#

Aside from the built-in way to install packages, we can also use 3rd party package managers, for example, straight.el.

To install straight.el, just put the following script to init.el:

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

To install a package, add the following statement to init.el:

(straight-use-package 'some-package)
;; for example, to install company-mode, use the following
(straight-use-package 'company)

Straight.el will install a package if it has not been installed yet.

Color, theme, modeline#

We can surly customize the look of Emacs via handcraft, e.g., change background color and foreground color:

(add-to-list 'default-frame-alist '(foreground-color . "#E0DFDB"))
(add-to-list 'default-frame-alist '(background-color . "#102372"))

More advanced way to customize color is to use or install a color theme. Emacs comes with several built-in themes.

To find good themes, MELPA is a good place to start. A good theme package is doom-themes. It comes with a lot of themes.

To load a theme, type A-x load-theme, and then type a theme name, for example, doom-one, or we can add to config:

(load-theme 'doom-gruvbox t nil)

To show currently enabled themes, run c-h v and type custom-enabled-themes to check.

File editing#

  • Delete a line: C-S-Backspace.
  • Go to line beginning and end: C-a and c-e.
  • Yank selected text and paste: M-w and c-y.

Evil mode#

I find the editing experience in Emacs highly inferior to that of Vim. So We can use emacs-evil:

(straight-use-package 'evil)

;; enable evil mode
(evil-mode 1)

There is in fact a built-in viper-mode for Emacs, but it is not complete as compared to evil.

Ref:

Window and buffer#

  • open a horizontal split: c-x 2
  • open a vertical split: c-x 3
  • close a buffer: c-x k
  • close a window: c-x 0
  • open a file: c-x c-f
  • create a new file: same as c-x c-f
  • save a file: c-x c-s
  • quit emacs: c-x c-c
  • Open a buffer: c-x b
  • To show config file path, run M-:, then type (buffer-file-name) to show config path.

Ref:

Help system#

c-h ? gives an overview of the help system.

  • Check the value of a variable: c-h v <variable-name>
  • Check function doc: c-h f
  • Check which command a key binds to: c-h c

Ref:

Tab completion#

Add the following to your emacs conf:

(setq completion-cycle-threshold 1)

Ref:

UI#

disable toolbar, menu bar, scrollbar#

Toolbar, menu bar and scrollbar are ugly and take precious space. Let’s disable them all together:

(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)

Ref:

Show line number and relative number#

Like what vim does:

(global-display-line-numbers-mode)
(setq display-line-numbers-type 'relative)

Ref:

Modeline#

What we call statusline in Vim, they call it modeline in Emacs. IMO, they are very similar concepts. We can use doom-modeline to help use customize the modeline.

First, we need to install some special icon that doom-modeline uses. We need to install package all-the-icons to install the fonts needed:

(straight-use-package 'all-the-icons)

Run M-x all-the-icons-install-fonts to install the icon fonts.

Then install doom-modeline:

(straight-use-package 'doom-modeline)

Ref:

Tabline#

For Emacs 27, add the following setting to init.el:

show trailing white space#

Add following config:

(setq-default show-trailing-whitespace t)

Ref:

https://stackoverflow.com/a/34589105/6064933

Auto-completion#

We can use package company to enable auto-completion for functions and options etc. Add the following setting to init.el:

;; enable company mode in all buffers
(add-hook 'after-init-hook 'global-company-mode)

;; use tab and s-tab to cycle forward and backward completion items
(add-hook 'after-init-hook 'company-tng-mode)

The company-tng-mode is used to make Tab and SHIFT-Tab to move forward and backward in the auto-completion menu, for more details see issue here and PR here.

fuzzy search#

If you have used Vim, you may be familiar with fzf.vim or LeaderF or telescope.nvim, depending which Vim distribution you are using. In Emacs, we can use ivy.

Here is a minimal config:

(straight-use-package 'ivy)
(straight-use-package 'counsel)

;; enable ivy mode by default
(ivy-mode 1)

Then ivy will be automatically enabled when you open file/buffer or run commands. Note that the default fuzzy search behavior of ivy is different from that of LeaderF or fzf. For example, to search package-install in ivy, you can type pac ins, but not pacins, the space between is important.

Parentheses: highlight and insert#

To highlight matching parentheses, add the following config:

;; show matching parentheses
(show-paren-mode t)

;; the style for matching parentheses
(set-face-background 'show-paren-match "#ff0000")
(set-face-attribute 'show-paren-match nil
            :weight 'bold :underline t :overline nil :slant 'normal)

To insert matching parentheses automatically, install package smartparens:

(straight-use-package 'smartparens)

;; enable smartparens mode
(smartparens-global-mode t)

To change, delete, add matching pairs easily, there is also evil-surround, mimicking the behavior of vim-surround by Tpope.

Ref:

Issues#

custom-set-faces is added automatically to init.el#

After installing packages, init.el is automatically updated and include custom-set-faces. We can use the following setting to disable this behavior:

(setq custom-file (locate-user-emacs-file "custom.el"))
(load custom-file)

Ref:

Change backup directory#

By default, Emacs saves a backup file in the same directory as the current file, which pollutes the current working directory. We can move the backup directory to a centralized directory:

;; change backup settings
(setq backup-directory-alist '(("." . "~/.cache/emacs-backups")))

Conclusion#

After learning and trying Emacs for one day, I would say that Emacs is truly a great GUI editor which has some really cool features. For example, in Emacs, you can set different font style (size, bold, italic, font family etc.) to different texts in the same buffer, which org-mode used for beautiful type-setting inside Emacs2. You can also get the vscode-like experience via customize groups.

However, when it comes to editting text and navigation, I think Vim/Nvim is still the king, the proof of which is apparent since we have got evil-mode in Emacs.

References#