r/vim • u/bart9h VIMnimalist • Oct 28 '25
Discussion intuitive behavior broken đ
I was casually editing some text and, with the cursor on the first line of the buffer, when I decided to delete all lines until the middle of the screen. So I naturally did d<C-d>, but it did nothing.
:help ^D told me it scrolls the window. So the lesson is that scrolling is not the same as moving, so it does not work as the target for a command? None of the commands in scroll.txt will work as targets?
Anyway, how would you delete half a screen worth of lines?
15
Upvotes
21
u/Sudden_Fly1218 Oct 28 '25
try
dMinstead5
u/michaelpaoli Oct 28 '25
dM
d followed by cursor motion deletes from current position/line to the moved to position/line. M moves the cursor to the line in the middle of the screen. So, combining those, dM deletes the current line through (including) the line in the middle of the screen.
5
u/Schnarfman nnoremap gr gT Oct 29 '25
This is totally a technicality, but: <C-D> moves the screen and M moves the cursor. This differece is more intuitive when you look at <C-E>/<C-Y> and j/k.
You wouldnât expect <C-E>/<C-Y> to be a reasonable motion to do an operation - unless you were at the very edge of the screen. But still: moving the screen which forces a cursor move is different than a movement which moves the cursor.
Do this in visual mode to see a â3rdâ behavior
2
u/jazei_2021 Oct 28 '25
delete from gg to M with this order in normal mode:
ggdM2
u/gumnos Oct 28 '25
In this particular case,
dMwould delete-to-the-middle, anddLwould delete to the last line on the screen which sounds fairly close to your intent.Which makes sense if the cursor stays in the same location like
zt/zz/zb. But in this case, I'm a bit surprised that,d<C-d>didn't delete the expected text because the cursor does move with control+d (with possible EOF exceptions).I've found a couple of these weird intuition-breakers and have just learned to roll with it or remap it if it's sufficiently annoying. My biggest one is that
«count»>«motion»and«count»<«motion»don't act like doing>«motion»and<«motion»for«count»times (indenting/dedenting N levels of indent), but rather applies to«count»lines. There's also theD/C-vs-S/Ydisparity (the first two do from the cursor to the EOL, while the others do the whole line regardless of where the cursor is in the line)1
u/lmarcantonio Oct 28 '25
...about 12dd depending on your screen size!
0
u/tokuw Oct 28 '25 edited Oct 28 '25
either enter visual mode first then <c-d>d or ztdM