This is kind of a long ramble about vim, and a little bit about the joy of forgetting and re-learning the basics.
I’ve been using vim regularly for nearly 20 years. I had an Asus 7″ Eee PC back in university and initially, after breaking out of its preinstalled Mandrake or Mandriva or whatever distro it had, I didn’t have any window management system at all. I was usually ssh’d into servers for schoolwork, so I had to use something terminal-based, and my style was far more walk around thumb-typing on the tiny keyboard than stopping to fumble complex meta key combos, so I fell for vim hard.
Somewhere a year or two into my vim journey, already an expert at :<line_no>
(goto line_no) and hjkl-movement, and dd
(cut a line) and yy
(yank a line) and 3dd
(cut 3 lines) and g=G
(go to top of the file, autoindent to the bottom of the file) and complex regex find and replaces like :10,20s/file:\(.*\).[a-z]\+/\1
(between lines 10 and 20 change patterns like file:hello.tgz
to hello
), somewhere in there, I learned about the grammar of vim, e.g. ciw
for “change in word
” or dt'
for “cut til '
“, and damn, I have to say, I felt I knew vim pretty good.
About 10 years ago, I started using Sublime Text 2 more frequently for professional work. I’d never been a big vim plugins guy (of course I had custom syntax colours!) but I wasn’t up on NERD tree and fzf plugins and goodness knows what else. I had developed the opinion that I liked vim because of its spartan, austere simplicity, and the guarantee it’d be the same no matter where I went.
Yeah, I was one of those people.
But Sublime Text 2 had a fuzzy filename search I could open by just typing command-p, and that was a revelation for me at the time. I suddenly saw codebases very, very differently: I only needed to know the gist of the name of the thing I was looking for to find the thing, fast. That and multiple cursors — I got even better with multiple cursors than I ever was with vim’s find and replace. I could slice and dice text like mad! I likely could have got the same things over in vim, too, but the (maybe imagined) barrier of plugin management system hell kept me at bay.
My vim skills languished.
I could still use vim fine, but over years, I stopped being anywhere near as comfortable or as fluid as I once had been. I wanted a mouse. I wanted my multiple cursors. I only ever opened vim in SSH sessions or for toy projects with <20 files.
Jump to yesterday: I’m working on a small game in Godot, editing my gdscript code in Godot’s built-in editor. I’m maintaining a TODO list in a text file outside of the editor, so of course I’m just opening in vim. As I write up lines of todos, I occasionally shuffle them around. To do that, I tend to initiate a visual selection of a few lines by hitting v
and select across them:
then I hit d
to cut
the lines:
and wow is it annoying how it omits the rest of the line. So I u
to undo, v
to re-enter visual selection, and then manually scroll my selection down and alllll the way across that last line:
Then I hit d
again:
there, that’s better. Got the whole line cut to move elsewhere.
And I think: Wyatt — you must be doing this wrong. You cannot really believe that in vim you’re supposed select character by character all the way to the end of the line, just to copy+paste a selected block of text in the most common way.
That critical voice was right! A brief search later, I’ve found at least two good options. Here they are:
First, I could use $
to pop the selection to the end of the line, which (along with its go-to-start complement, ^
) I almost never use, because almost every time I’m jumping to the end or start of a line I want to get into insert mode, so I instead use SHIFT+a
(go to end and enter insert) or SHIFT+i
(go to beginning and enter insert), then my dumb hands actually hit ESC
very often to get back to command mode when I didn’t want to insert!
Second, and I think this is even better: using D instead of d will just cut directly to the end of the line. So I can be here (at the initial spot I was in, with a visual selection at the start of a line I want to cut):
and just hit D
instead of d
, and then I go straight to here, with the line cut:
These are very basic things. Tiny facts. I think I likely even knew them at points in the past, but somewhere along the way I forgot how to use them in concert. Maybe I managed to skip right by them in the first place, or all along, and just never the pieces together in this way. Seeing them here, I think: well this is obvious. This is the way I’m going to do it forever. But who knows? Maybe I’ve thought that before.
As is often said, learning vim is a lifelong journey. But that’s not just true in the ways you know it is; it’s also true in new ways, which you only discover as you go along.
—
As a post script, of course I know I could just use the commands 3dd
, (or 3D
) to “cut 3 lines
” and get the same result even faster. I even mentioned 3dd
way up above! But I very rarely have a clear “I want this many lines” mindset when editing text idly. I tend to start selecting text, and I know what I want when I see it.