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]

Opening Files in Vim

When you launch Vim It’s important that you always launch Vim from the command line and at the root of your project. I’ll explain why later in the section on projects, but for now just remember to start your work from there. From your shell We already saw this one in the hello world: $ mvim path/to/file.txt Every time you do this you’ll open up a new window. [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 called from near 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 Buffers

You can think of a buffer as a piece of text loaded into memory. They’re especially useful when you need to move text between files using Vim’s built-in copy / paste functionality. You can yank and put between any buffers in the system, but you can’t do it between buffers in other windows. For example. I have two windows open in MacVim (this could be two separate terminal windows too). [Read More]

Vim help when help is needed

Before I started writing this I thought “Vim’s got good help docs, people just tend to ignore them.” I should print them out and use them as a reference while writing this. Then I discovered there were 2,956 pages of them. After spending a fair amount of time spelunking through :help for this site, I’ve finally begun to understand why people mostly ignore Vim’s thousands of pages of help. It’s because they’re not help docs, at least not in the traditional sense. [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 Leader Key (wtf is it?)

Sooner or later you’re going to hear mention of the leader key. In vimscript it looks like <Leader>. You can think of it as a trigger, or maybe a shortcut. macOS has the command key (⌘). Vim has the <Leader> key. You type it, and then usually two or three more characters to trigger some behavior like saying ⌘+o to open a file. By default it is set to backslash \\ Lots of people remap it to something else that they find easier to type or remember. [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]