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

推荐订阅源

月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
T
Tailwind CSS Blog
博客园_首页
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
J
Java Code Geeks
量子位
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
C
Check Point Blog
V
Visual Studio Blog
H
Help Net Security
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta

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
Binding Keys in Zsh
2019-06-13 · via jdhao's digital space

In this post, I want to share how to use bindkeys command to solve a few issues when using Zsh.

Can not use HOME and END keys normally#

After using Zsh, I found that some terminals can not understand Home and End keys correctly, i.e., I can not go to the beginning or end of a line by pressing Home or End key.

This is because the key codes that terminal recognizes when you press certain keys can not be recognized by Zsh. You can manually find which key code is sent when you press a key. You can use showkey -a to print the key codes. Here is what it shows when I press Home and End keys.

After we know the key codes for these two keys, we can bind the codes to the operation we want to perform, that is begin-of-line and end-of-line. Add the following settings to your .zshrc:

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Bind key to run a custom command#

One reader of this post asked a question on how to use shortcut keys to run the following command:

I searched the web and found a solution. Suppose that we want to bind Ctrl + O to the above command, we can add the following setting to .zshrc:

bindkey -s '^o' 'nvim $(fzf)^M'
# you may also use the following one
# bindkey -s '^o' 'nvim $(fzf)\n'

In the above setting, -s option is used to translate the input string to output string so that when you press the shortcut, it is replaced with the command you want to run. ^M or \n is used to represent the Enter key so that the command is run automatically.

References#