Marks

Marks are, in essence, in-page bookmarks that you can use to quickly jump between important parts of your file(s). They have one non-trivial problem. You can’t easily see them while working on your document. Fortunately, there’s a plugin for that. Before we continue, let’s get a bit more specific about what a mark is. A mark is a named cursor location. There are local, and global marks. Each mark is named with a single letter between a and z in the English alphabet. [Read More]

Split Window Aesthetics

Split Windows are one of the killer features of Vim, that surprisingly few editors get right. The default aesthetics though… they could use some work. It’s not obvious which split is active, and the divider is either too visible, or not visible enough. Quick! Which split is active? To me, it’s not obvious at all. Of course, this is Vim, and we can do better than just accept the defaults. [Read More]

Setting values, and running commands, for a specific filetype

Sometimes you want to configure something for a specific filetype. For example, you might want to have the default textwidth set to 80 characters for Ruby files, but 120 for markdown. More advanced users may want to have custom functions run for a specific filetype. The best location for this is ~/.vim/ftplugin/<filetype>.vim In this case <filetype> is the name of the filetype not the extension. If you’re not sure what the official name of a filetype is you can ask vim by opening a file of that type and saying :set filetype? [Read More]

Using Markdown in Vim

Vim does a pretty good job of giving you a stylized preview of your Markdown. Especially when you consider the inherent limitations of an editor that must be able to run within the terminal. For example: Note that italics are handled differently in terminal Vim, because most terminals can’t display italics. If you prefer a more streamlined look, where your text isn’t cluttered by formatting characters for your bold and italic text you can “conceal them. [Read More]

Wrapping Text In Vim

Terminology: Hard Wrap vs Soft Wrap A “soft” wrap is when your text editor just makes the text look like it has been wrapped at the edge of the screen, when in reality it’s just one very long line. This is pretty obvious when line numbers are turned on because there are multiple lines of text but the line number to the left doesn’t increase. A “hard” wrap is when your text editor is configured to actually insert a newline character \n at a predefined width. [Read More]

Showing Invisible Things In Vim

Showing normal invisible characters Sometimes you want to see invisible things. Imagine you’re programming in Python, where it really matters if something is indented with spaces or tabs and the number used matters too. First we turn on list. Sadly, I can’t tell you why. The help docs are all about using lists in VimScript and not what this command does. What I can tell you is that this stuff doesn’t work without it. [Read More]

Vim Registers

If you haven’t done so already, I’d recommend reading the section on “buffers” first. Registers are very similar to buffers they’re just accessed a bit differently. The Yank & Delete Registers (The rolling clipboard) Unnamed Registers When you delete lines of text you are also pushing them onto a stack of 9 numbered registers. Think of it as a rolling clipboard containing the last 9 items. You can put any of the last 9 yanks or deletions into the current text by saying "<num>p where <num> is the number of the register you want to paste. [Read More]

Configuring Vim

Configuring Vim A coworker recently said To change config in vim, you have to be a power user - including understanding how to configure plugins. I’m sorry to say that he is not alone in this belief. Vim won’t hold your hand by giving you a bunch of preferences windows with checkboxes to turn functionality on and off. So, yes it is “harder”, but it absolutely does not require “Power User” levels of understanding. [Read More]

Cursor Movement in Vim

Before we discuss some of the more common, and useful, ones, remember that movement commands become even more valuable when combined with Vim’s verbs. In addition to verbs like Delete, you can combine most of the movement commands with numbers. For example, To jump 30 characters to the right you could say 30→ That’s a silly use-case, but moving down 2 paragraphs? That’s useful. This gets even more useful when we start using visual mode to select sections of text. [Read More]

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]