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

推荐订阅源

腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
The Cloudflare Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
Jina AI
Jina AI
V
V2EX
罗磊的独立博客
V
Visual Studio Blog
A
About on SuperTechFans
IT之家
IT之家
P
Proofpoint News Feed
B
Blog
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Y
Y Combinator 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
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#