Cut, Copy, & Paste in Vim

Cut, Copy, & Paste Before we get to any of these, remember that in a graphical Vim client like MacVim all your normal OS cut, copy, and paste commands like ⌘x, ⌘c, and ⌘v (on the Mac) will work just fine when combined with mouse selections. The following commands will make a huge difference in your speed because, they’ll enable you to efficiently rearrange code without ever reaching for the mouse. [Read More]

Line Numbers in Vim

Geeks like line numbers. I think Vim geeks really like line numbers, because we use them for more than just finding a specific place in the code. Jumping to a line number Out-of-the-box you’ve got three choices. Just pick the one you like best and don’t worry about remembering the others. I’ve used the 1st one for years and never had any need for the others. Minimal typing Type the number of the line you want to go to followed by capital G. [Read More]

Searching in Vim

In most editors searching is just a way to ask your editor where you can find something. In Vim it’s also a tool for extending your selection, deleting chunks, and more. That probably sounds weird, and slow, but trust me. Once you get the used to it, it’s spectacular, and well cover it in the sections on Cut, Copy, Paste and visual mode. Vim’s default search behavior is, in my opinion, excessively restrictive, and unhelpful. [Read More]

Split Windows In Vim

Split windows are one of my favorite features. Many modern editors allow you to see multiple documents on the same screen in a “split window” but very few of them allow you to see different parts of the same document in split windows. I find this to be incredibly useful when working on large class files. Imagine you’ve got an unfamiliar method defined near the bottom of a file, but it is called from the top of the file. [Read More]

Undo in Vim

Undo & Redo Sooner or later you’re going to make a mistake. I’m sorry to hit you with these hard truths, but well, we’ve just got to accept them and move on. Before we get to any of these, remember that in a graphical Vim client like MacVim all your normal OS undo, redo commands like ⌘z and ⌘⇧z on the Mac will work just fine. The following commands are a little faster (some of them at least) and will work in the terminal too, but if you’re still just getting started I encourage you to come back to this section later. [Read More]

Vim's Change, Replace & Substitute

Change, Substitute, & Replace… Read this after you’ve familiarized yourself with Delete, Yank, and Put (Cut, Copy, And Paste) Change Change (c) is similar to Delete. The difference is that Delete tells Vim “I want to get rid of this and go away.” Change says “I want to get rid of this and replace it with something else.” The practical difference is that after telling Vim what you want to change, it puts you into Insert mode so that you can start entering the replacement text. [Read More]

Vim's Visual Mode

Visual mode is what Vim calls it when you’re making a visual selection. It doesn’t matter if you’re defining the selection with a mouse or the keyboard, it’s still called “Visual” mode. Plain Visual Mode When you click-drag on some text in a modern editor you are creating a “visual selection”. We tend to just say “selection” because everything is “visual” in a modern editor, and it would be a meaningless redundancy. [Read More]

Visual Block Mode

Visual block mode allows you to select any arbitrary rectangular selection in your document. Most of the time it’s not very useful, but when you’re editing something like a CSV file, it can be pretty awesome. Visual Block mode always maintains a rectangular selection. Imagine that your text editor isn’t a collection of lines, but a grid filled with characters. You can draw a rectangle on that grid and select all the characters in that rectangle. [Read More]