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

推荐订阅源

月光博客
月光博客
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
MyScale Blog
MyScale Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
I
InfoQ
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security

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
Exclusive and Inclusive Motion in Neovim/Vim
2019-05-18 · via jdhao's digital space

Introduction#

Suppose that we have the following text in normal mode (cursor is indicated by ^):

If we use dw, we delete hello<Space>1 and only world is left; if we use de, hello is deleted and <Space>world is left. Have you ever wondered about why dw do not delete w while de will delete the o in hello? It seems that motion e and w are somewhat inconsistent in their behaviours. It turns out that it has something to do with the exclusivity of motions in Vim.

Most Vim motions are either exclusive or inclusive. This nature of a motion is best revealed when you perform an operation (these operations include, but are not limited to c, d, y) followed by these motions. Inclusive means that the texts between the start and end position of the cursor is used for that operation, while exclusive means that the last character near the end of current buffer2 is not included in the operation.

If you had known the above difference between the exclusive and inclusive motion, you would not be surprised about the so called inconsistency between dw and de. The reason is that w is an exclusive motion and e is an inclusive motion. Someone has asked on the Stack Exchange site on why backward delete such db can not delete the character in the cursor position. That is also because b is an exclusive motion so that the last character toward the end of the buffer is not included.

Change the exclusivity of a motion#

To force an exclusive motion to be inclusive or vice versa, you can prepend the motion by v (from Vim doc):

v       When used after an operator, before the motion command: Force
        the operator to work characterwise, also when the motion is
        linewise.  If the motion was linewise, it will become
        |exclusive|.
        If the motion already was characterwise, toggle
        inclusive/exclusive.  This can be used to make an exclusive
        motion inclusive and an inclusive motion exclusive.

Take the case in the first paragraph for an example, dvw will delete hello<Space>w (w becomes inclusive) and dve will delete only hell (e becomes exclusive). To find more detailed doc on this behaviour, read :h exclusive carefully.

References#