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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
Vercel News
Vercel News
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
C
Check Point Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Last Week in AI
Last Week in AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件

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
Introducing better-esacape.vim: My First Vim/Neovim Plugin
2020-12-18 · via jdhao's digital space

After using and learning Neovim for over 2 years, I have finally published my first plugin – better-escape.vim.

Better-escape.vim is a plugin to help users escape from insert mode quickly without experiencing the lagging that comes with Vim mappings.

As a Vim user, a very popular mapping to escape insert mode is to map jj or jk or kj etc. to Esc, since the Esc key is hard to reach without moving your hand from the home row.

inoremap jk <ESC>
inoremap jj <ESC>
inoremap kj <ESC>

However, this comes with an annoyance. If you use jk to escape insert mode, whenever you press j in insert mode, Vim will not write it to the buffer, it will wait for timeoutlen milliseconds to see whether you want to use the jk mapping or you want to input j literally. This issue is easily noticeable when we have a relatively large timeoutlen value.

In my previous post, I have already talked about this topic and provided a solution. The solution is to use an insert mode mapping for k only. When we press k, we check if the previous character is j. If that is true, we will erase previous j and go to normal mode. Otherwise, k is inserted as is. There is no lagging any more. The problem is that now we can not input jk directly in insert mode. To insert k when the previous character is j, we need to press Ctrl-V, then press j.

In better-escape.vim, I have a smarter solution. We will check the time spent between pressing j and k in insert mode. If the time is above a predefined threshold, jk will be inserted literally. Otherwise, we will escape from insert mode. With this plugin, you can easily customize the shortcut for escaping insert mode, as well as the time threshold used.