Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active June 16, 2024 20:15
Show Gist options
  • Save romainl/1f93db9dc976ba851bbb to your computer and use it in GitHub Desktop.
Save romainl/1f93db9dc976ba851bbb to your computer and use it in GitHub Desktop.
Vim: available key pairs in normal mode…

Vim: available key pairs in normal mode

All lowercase

The operators c, d, and y expect a motion, like w, e, etc. The second character in the following pairs is not a motion so it is a NOP and nothing is overridden if we use them in mappings.

cd cm co cp cq cr cs cu cx cy cz

dc dm dq dr ds du dx dy dz

yc yd ym yo yp yq yr ys yu yx yz

v is not an operator but it has similar semantics. There are fewer available pairs, though, because it is possible to use an operator right after v.

vm vo vq vv vz

Vi didn't have anything assigned to g so Vim kind of treated the namespace as a dumpster for new two-characters commands. Here are the pairs that are left:

gb gc gl gs gy

z was free, too, and it got the same treatment, with an even worse outcome:

zq

All UPPERCASE

[WIP]

ZA ZB ZC ZD ZE ZF ZG ZH ZI ZJ ZK ZL ZM ZN ZO ZP ZR ZS ZT ZU ZV ZW ZX ZY

Mixed case

[WIP]

@kiryph
Copy link

kiryph commented Mar 7, 2018

What about cs and ds?

Popular plugins which use some of them:

  • commentary: gc
  • surround: ys, cs and, ds
  • abolish: cr
  • exchange: cx
  • lion: gl

Formerly

The article Follow My Leader by Drew Neil about custom vim mappings points this out as well. See also his slides https://speakerdeck.com/nelstrom/follow-my-leader (slide 9 and 10) from a talk he gave about this. The video of the talk on vimeo is unfortunately no longer available.

@chrisbra
Copy link

zp zy

those have just been added for yanking / pasting without padding

@romainl
Copy link
Author

romainl commented Jun 23, 2021

Thank you @chrisbra.

@romainl
Copy link
Author

romainl commented Jun 23, 2021

@kiryph, thank you for pointing cs and ds out.

@jchros
Copy link

jchros commented Dec 2, 2022

I don't think that cv, dv and yv are available since operators can be followed by v to make the motions they operate on linewise/charwise. vc, vd, vp, vr, vs, vu, vx and vy aren't available either (they're operators used in visual mode), and can be useful when preceded by a count (since that selects count times as many characters as the previous selection in the same visual mode).

@romainl
Copy link
Author

romainl commented Dec 3, 2022

@jchros all good points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment